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

Subversion Repositories alternascope

[/] [alternascope/] [branches/] [Alpha/] [VGA/] [d_VGAdriver.v] - Blame information for rev 30

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 smpickett
//==================================================================//
2
// File:    d_VGAdriver.v                                           //
3 14 smpickett
// Version: 0.0.0.3                                                 //
4 8 smpickett
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -//
5
// Copyright (C) Stephen Pickett                                    //
6
//   Jun 09, 2005                                                   //
7
//                                                                  //
8
// This program is free software; you can redistribute it and/or    //
9
// modify it under the terms of the GNU General Public License      //
10
// as published by the Free Software Foundation; either version 2   //
11
// of the License, or (at your option) any later version.           //
12
//                                                                  //
13
// This program is distributed in the hope that it will be useful,  //
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of   //
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    //
16
// GNU General Public License for more details.                     //
17
//                                                                  //
18
// If you have not received a copy of the GNU General Public License//
19
// along with this program; write to:                               //
20
//     Free Software Foundation, Inc.,                              //
21
//     51 Franklin Street, Fifth Floor,                             //
22
//     Boston, MA  02110-1301, USA.                                 //
23
//                                                                  //
24
//------------------------------------------------------------------//
25
// Revisions:                                                       //
26
// Ver 0.0.0.1     Apr 28, 2005   Under Development                 //
27
//     0.0.0.2     Jun 09, 2005   Cleaning                          //
28 11 smpickett
//     0.0.0.3     Jun 10, 2005   Re-structuerd the VCNT and HCNT   //
29
//                                so they line up with the PXLs.    //
30 8 smpickett
//                                                                  //
31
//==================================================================//
32
 
33 2 smpickett
module Driver_VGA(
34
    CLK_50MHZ, MASTER_RST,
35 11 smpickett
    CLK_VGA,
36 2 smpickett
    VGA_RAM_DATA, VGA_RAM_ADDR,
37
    VGA_RAM_OE, VGA_RAM_WE, VGA_RAM_CS,
38
    VGA_RAM_ACCESS_OK,
39
    H_SYNC, V_SYNC, VGA_OUTPUT,
40 17 smpickett
    XCOORD, YCOORD,
41 2 smpickett
    TRIGGER_LEVEL,
42 27 smpickett
    VERT_OFFSET,
43
    HORZ_OFFSET,
44 11 smpickett
    SHOW_LEVELS,
45
    HCNT, VCNT,
46
    RGB_CHAR
47 2 smpickett
    );
48
 
49
//==================================================================//
50
// PARAMETER DEFINITIONS                                            //
51
//==================================================================//
52
parameter P_black   = 3'b000;
53
parameter P_yellow  = 3'b110;
54
parameter P_cyan    = 3'b011;
55
parameter P_green   = 3'b010;
56
parameter P_white   = 3'b111;
57
 
58
//==================================================================//
59
// VARIABLE DEFINITIONS                                             //
60
//==================================================================//
61
//----------------------//
62
// INPUTS / OUTPUTS     //
63
//----------------------//
64
input CLK_50MHZ;                // System wide clock
65
input MASTER_RST;               // System wide reset
66 11 smpickett
input CLK_VGA;
67 2 smpickett
output H_SYNC;                  // The H_SYNC timing signal to the VGA monitor
68
output V_SYNC;                  // The V_SYNC timing signal to the VGA monitor
69
output[2:0]  VGA_OUTPUT;        // The 3-bit VGA output
70
input[11:0]  XCOORD, YCOORD;
71
input[15:0]  VGA_RAM_DATA;
72
output[17:0] VGA_RAM_ADDR;
73
output VGA_RAM_OE, VGA_RAM_WE, VGA_RAM_CS;
74
output VGA_RAM_ACCESS_OK;
75 27 smpickett
input[9:0] TRIGGER_LEVEL, HORZ_OFFSET, VERT_OFFSET;
76 2 smpickett
input SHOW_LEVELS;
77 11 smpickett
output[9:0] HCNT, VCNT;
78
input[2:0] RGB_CHAR;
79 2 smpickett
 
80
 
81
 
82
 
83
//----------------------//
84
// WIRES / NODES        //
85
//----------------------//
86
reg H_SYNC, V_SYNC;
87
reg [2:0]  VGA_OUTPUT;
88
wire CLK_50MHZ, MASTER_RST;
89 11 smpickett
wire CLK_VGA;
90 2 smpickett
wire[11:0] XCOORD, YCOORD;
91
wire[15:0] VGA_RAM_DATA;
92
reg[17:0]  VGA_RAM_ADDR;
93
reg VGA_RAM_OE, VGA_RAM_WE, VGA_RAM_CS;
94
reg VGA_RAM_ACCESS_OK;
95 27 smpickett
wire[9:0] TRIGGER_LEVEL, HORZ_OFFSET, VERT_OFFSET;
96 2 smpickett
wire SHOW_LEVELS;
97 11 smpickett
wire[9:0] HCNT, VCNT;
98
wire[2:0] RGB_CHAR;
99 2 smpickett
 
100
 
101
//----------------------//
102
// REGISTERS            //
103
//----------------------//
104 11 smpickett
wire CLK_25MHZ = CLK_VGA;
105 2 smpickett
reg [9:0] hcnt;     // Counter - generates the H_SYNC signal
106
reg [9:0] vcnt;     // Counter - counts the H_SYNC pulses to generate V_SYNC signal
107
reg[2:0]  vga_out;
108
 
109
//==================================================================//
110
// FUNCTIONAL DEFINITIONS                                           //
111
//==================================================================//
112 11 smpickett
assign HCNT = hcnt;
113
assign VCNT = vcnt;
114 2 smpickett
 
115
 
116
//------------------------------------------------------------------//
117
// SYNC TIMING COUNTERS                                             //
118
//------------------------------------------------------------------//
119
always @ (posedge CLK_25MHZ or posedge MASTER_RST) begin
120
    if (MASTER_RST == 1'b1) begin
121
        hcnt <= 10'd0;
122 11 smpickett
        vcnt <= 10'd430;
123 2 smpickett
    end else if (hcnt == 10'd0799) begin
124
        hcnt <= 10'd0;
125 11 smpickett
        if (vcnt == 10'd0)
126
            vcnt <= 10'd520;
127 2 smpickett
        else
128 11 smpickett
            vcnt <= vcnt - 1'b1;
129 2 smpickett
    end else
130
        hcnt <= hcnt + 1'b1;
131
end
132
 
133
 
134
//------------------------------------------------------------------//
135
// HORIZONTAL SYNC TIMING                                           //
136
//------------------------------------------------------------------//
137
always @ (hcnt)
138 11 smpickett
    if (hcnt >= 10'd656 && hcnt <= 10'd751)
139 2 smpickett
        H_SYNC = 1'b0;
140
    else
141
        H_SYNC = 1'b1;
142
 
143
 
144
//------------------------------------------------------------------//
145
// VERTICAL SYNC TIMING                                             //
146
//------------------------------------------------------------------//
147
always @ (vcnt)
148 11 smpickett
    if (vcnt == 10'd430 || vcnt == 10'd429)
149 2 smpickett
        V_SYNC = 1'b0;
150
    else
151
        V_SYNC = 1'b1;
152
 
153
 
154
//------------------------------------------------------------------//
155
// VGA DATA SIGNAL TIMING                                           //
156
//------------------------------------------------------------------//
157 27 smpickett
always @ (hcnt or vcnt or XCOORD or YCOORD or MASTER_RST or vga_out or SHOW_LEVELS or TRIGGER_LEVEL or VERT_OFFSET or HORZ_OFFSET or RGB_CHAR) begin
158 2 smpickett
    if(MASTER_RST == 1'b1) begin
159
        VGA_OUTPUT = P_black;
160
    //------------------------------------------------------------------------------//
161
    // UNSEEN BORDERS                                                               //
162 11 smpickett
    end else if( (vcnt >= 10'd400) && (vcnt <= 10'd440) ) begin
163 2 smpickett
        VGA_OUTPUT = P_black;
164 11 smpickett
    end else if( (hcnt >= 10'd640) ) begin
165 2 smpickett
        VGA_OUTPUT = P_black;
166
    //------------------------------------------------------------------------------//
167
    // MOUSE CURSORS                                                                //
168 11 smpickett
    end else if(vcnt == YCOORD) begin
169 2 smpickett
        VGA_OUTPUT = P_green;
170 11 smpickett
    end else if(hcnt == XCOORD) begin
171 2 smpickett
        VGA_OUTPUT = P_green;
172
    //------------------------------------------------------------------------------//
173
    // TRIGGER SPRITE         (shows as ------T------ )                             //
174 11 smpickett
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (TRIGGER_LEVEL) && hcnt != 10'd556 && hcnt != 10'd558) begin
175 2 smpickett
        VGA_OUTPUT = P_yellow;
176 11 smpickett
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (TRIGGER_LEVEL+1'b1) && hcnt >= 10'd556 && hcnt <= 10'd558) begin
177 2 smpickett
        VGA_OUTPUT = P_yellow;
178 11 smpickett
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (TRIGGER_LEVEL-1'b1) && hcnt == 10'd557) begin
179 2 smpickett
        VGA_OUTPUT = P_yellow;
180
    //------------------------------------------------------------------------------//
181 27 smpickett
    // VERTICAL OFFSET SPRITE         (shows as ------V------ )                     //
182
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (VERT_OFFSET) && hcnt != 10'd560) begin
183
        VGA_OUTPUT = P_yellow;
184
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (VERT_OFFSET+1'b1) && (hcnt == 10'd559 || hcnt == 10'd561)) begin
185
        VGA_OUTPUT = P_yellow;
186
    end else if(SHOW_LEVELS == 1'b1 && vcnt == (VERT_OFFSET-1'b1) && hcnt == 10'd560) begin
187
        VGA_OUTPUT = P_yellow;
188
   //------------------------------------------------------------------------------//
189
    // HORIZONTAL1 OFFSET SPRITE         (shows as ------H------ )                 //
190
    end else if(SHOW_LEVELS == 1'b1 && hcnt == (HORZ_OFFSET) && vcnt != 10'd102 && vcnt != 10'd100) begin
191
        VGA_OUTPUT = P_yellow;
192
    end else if(SHOW_LEVELS == 1'b1 && hcnt == (HORZ_OFFSET+1'b1) && (vcnt == 10'd100 || vcnt == 10'd101 || vcnt == 10'd102)) begin
193
        VGA_OUTPUT = P_yellow;
194
    end else if(SHOW_LEVELS == 1'b1 && hcnt == (HORZ_OFFSET-1'b1) && (vcnt == 10'd100 || vcnt == 10'd101 || vcnt == 10'd102)) begin
195
        VGA_OUTPUT = P_yellow;
196
    //------------------------------------------------------------------------------//
197 2 smpickett
    // TOP, BOTTOM, LEFT AND RIGHT GRID LINES                                       //
198 11 smpickett
    end else if(vcnt == 10'd0 || vcnt == 10'd399 || vcnt == 10'd441) begin
199 2 smpickett
        VGA_OUTPUT = P_cyan;
200 11 smpickett
    end else if(hcnt == 10'd0 || hcnt == 10'd639) begin
201 2 smpickett
        VGA_OUTPUT = P_cyan;
202
    //------------------------------------------------------------------------------//
203 17 smpickett
    // CHARACTER DISPLAY
204
    end else if(vcnt <= 10'd520 && vcnt >= 10'd441) begin
205
        VGA_OUTPUT = RGB_CHAR;
206
    //------------------------------------------------------------------------------//
207
    // THE WAVEFORM                                                                 //
208
    end else if(vga_out != 0) begin
209
        VGA_OUTPUT = vga_out;
210
    //------------------------------------------------------------------------------//
211 2 smpickett
    // MIDDLE GRID LINES (dashed at 8pxls)                                          //
212 11 smpickett
    end else if(vcnt == 10'd199 && hcnt[3] == 1'b1) begin
213 2 smpickett
        VGA_OUTPUT = P_cyan;
214 11 smpickett
    end else if((hcnt == 10'd319) && (vcnt <= 10'd399) && (vcnt[3] == 1'b1)) begin
215 2 smpickett
        VGA_OUTPUT = P_cyan;
216
    //------------------------------------------------------------------------------//
217
    // OTHER HORIZONTAL LINES (dashed at 4pxls)                                     //
218 11 smpickett
    end else if((vcnt == 10'd39 || vcnt == 10'd79 || vcnt == 10'd119 || vcnt == 10'd159 || vcnt == 10'd239 || vcnt == 10'd279 || vcnt == 10'd319 || vcnt == 10'd359) && (hcnt[2] == 1'b1)) begin
219 2 smpickett
        VGA_OUTPUT = P_cyan;
220
    //------------------------------------------------------------------------------//
221
    // OTHER VERTICAL LINES (dashed at 4pxls)                                       //
222 11 smpickett
    end else if(((hcnt[5:0] == 6'b111111) && (vcnt <= 10'd399)) && (vcnt[2] == 1'b1)) begin
223 2 smpickett
        VGA_OUTPUT = P_cyan;
224
    //------------------------------------------------------------------------------//
225
    // OTHERWISE...                                                                 //
226
    end else
227
        VGA_OUTPUT = P_black;
228
end
229
 
230
//------------------------------------------------------------------//
231
// RAM DATA READING                                                 //
232
//------------------------------------------------------------------//
233
// on reset, ram_addr = 24 and add 25 on each pxl
234
//     row 0: ram_addr = 24 and 25 for each pxl
235
//     row 1: ram_addr = 24 and 25 for each pxl
236
//       ...
237
//     row 15: ram_addr = 24 and 25 for each pxl
238
//     row 16: ram_addr = 23 and 25 for each pxl *
239
//     row 17: ram_addr = 23 and 25 for each pxl *
240
//       ...
241
reg[4:0]  ram_vcnt;
242
reg[15:0] ram_vshift;
243
 
244
always @ (posedge CLK_25MHZ or posedge MASTER_RST) begin
245
    if(MASTER_RST == 1'b1) begin
246
        ram_vshift <= 16'h8000;
247 11 smpickett
    end else if(vcnt > 10'd399) begin
248 2 smpickett
        ram_vshift <= 16'h8000;
249 17 smpickett
    end else if(/*(vcnt <= 10'd399) && */(hcnt == 10'd640)) begin
250 2 smpickett
        if(ram_vshift == 16'h0001)
251
            ram_vshift <= 16'h8000;
252
        else
253
            ram_vshift <= (ram_vshift >> 1);
254
    end else
255
        ram_vshift <= ram_vshift;
256
end
257
 
258
always @ (posedge CLK_25MHZ or posedge MASTER_RST) begin
259
    if(MASTER_RST == 1'b1) begin
260 17 smpickett
        ram_vcnt <= 5'd24;//5'b0
261
    end else if(vcnt > 10'd399) begin
262
        ram_vcnt <= 5'd24;
263
    end else if(/*(vcnt >= 10'd30) &&*/ (hcnt == 10'd640) && (ram_vshift == 16'h0001)) begin
264 2 smpickett
        if(ram_vcnt == 5'd0)
265
            ram_vcnt <= 5'd24;
266 17 smpickett
        else
267 2 smpickett
            ram_vcnt <= ram_vcnt - 1'b1;
268
    end else begin
269
        ram_vcnt <= ram_vcnt;
270
    end
271
end
272
 
273
 
274
 
275 11 smpickett
always @ (hcnt or ram_vcnt) begin
276
    VGA_RAM_ADDR = ram_vcnt + (hcnt * 7'd25);
277 17 smpickett
//    VGA_RAM_ADDR = vcnt * hcnt;
278 2 smpickett
end
279
 
280
 
281
always @ (VGA_RAM_DATA or ram_vshift) begin
282
    if((VGA_RAM_DATA & ram_vshift) != 16'b0)
283
        vga_out = P_white;
284
    else
285
        vga_out = 3'b0;
286
end
287
 
288
 
289
always begin
290
    VGA_RAM_CS = 1'b0;  // #CS
291
    VGA_RAM_OE = 1'b0;  // #OE
292
    VGA_RAM_WE = 1'b1;  // #WE
293
end
294
 
295
 
296
//------------------------------------------------------------------//
297
// ALL CLEAR?                                                       //
298
//------------------------------------------------------------------//
299
always @ (vcnt) begin
300 17 smpickett
    if(vcnt > 10'd399)
301 2 smpickett
        VGA_RAM_ACCESS_OK = 1'b1;
302
    else
303
        VGA_RAM_ACCESS_OK = 1'b0;
304
end
305
 
306
 
307
endmodule

powered by: WebSVN 2.1.0

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