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

Subversion Repositories vga_lcd

[/] [vga_lcd/] [trunk/] [rtl/] [verilog/] [vga_curproc.v] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 31 rherveille
/////////////////////////////////////////////////////////////////////
2
////                                                             ////
3
////  WISHBONE rev.B2 compliant enhanced VGA/LCD Core            ////
4
////  Hardware Cursor Processor                                  ////
5
////                                                             ////
6
////  Author: Richard Herveille                                  ////
7
////          richard@asics.ws                                   ////
8
////          www.asics.ws                                       ////
9
////                                                             ////
10
////  Downloaded from: http://www.opencores.org/projects/vga_lcd ////
11
////                                                             ////
12
/////////////////////////////////////////////////////////////////////
13
////                                                             ////
14
//// Copyright (C) 2002 Richard Herveille                        ////
15
////                    richard@asics.ws                         ////
16
////                                                             ////
17
//// This source file may be used and distributed without        ////
18
//// restriction provided that this copyright statement is not   ////
19
//// removed from the file and that any derivative work contains ////
20
//// the original copyright notice and the associated disclaimer.////
21
////                                                             ////
22
////     THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY     ////
23
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   ////
24
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   ////
25
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      ////
26
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         ////
27
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    ////
28
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   ////
29
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        ////
30
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  ////
31
//// LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  ////
32
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  ////
33
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         ////
34
//// POSSIBILITY OF SUCH DAMAGE.                                 ////
35
////                                                             ////
36
/////////////////////////////////////////////////////////////////////
37
 
38
//  CVS Log
39
//
40 53 rherveille
//  $Id: vga_curproc.v,v 1.4 2003-05-07 09:48:54 rherveille Exp $
41 31 rherveille
//
42 53 rherveille
//  $Date: 2003-05-07 09:48:54 $
43
//  $Revision: 1.4 $
44 31 rherveille
//  $Author: rherveille $
45
//  $Locker:  $
46
//  $State: Exp $
47
//
48
// Change History:
49
//               $Log: not supported by cvs2svn $
50 53 rherveille
//               Revision 1.3  2002/03/04 16:05:52  rherveille
51
//               Added hardware cursor support to wishbone master.
52
//               Added provision to turn-off 3D cursors.
53
//               Fixed some minor bugs.
54
//
55 34 rherveille
//               Revision 1.2  2002/03/04 11:01:59  rherveille
56
//               Added 64x64pixels 4bpp hardware cursor support.
57
//
58 33 rherveille
//               Revision 1.1  2002/02/16 10:40:00  rherveille
59
//               Some minor bug-fixes.
60
//               Changed vga_ssel into vga_curproc (cursor processor).
61
//
62 31 rherveille
//               Revision 1.1  2002/02/07 05:42:10  rherveille
63
//               Fixed some bugs discovered by modified testbench
64
//               Removed / Changed some strange logic constructions
65
//               Started work on hardware cursor support (not finished yet)
66
//               Changed top-level name to vga_enh_top.v
67
//
68
 
69 53 rherveille
//synopsys translate_off
70 31 rherveille
`include "timescale.v"
71 53 rherveille
//synopsys translate_on
72 31 rherveille
 
73
module vga_curproc (clk, rst_i, Thgate, Tvgate, idat, idat_wreq,
74 33 rherveille
        cursor_xy, cursor_en, cursor_res,
75
        cursor_wadr, cursor_wdat, cursor_we,
76
        cc_adr_o, cc_dat_i,
77 31 rherveille
        rgb_fifo_wreq, rgb);
78
 
79
        //
80
        // inputs & outputs
81
        //
82
 
83
        // wishbone signals
84
        input         clk;           // master clock input
85
        input         rst_i;         // synchronous active high reset
86
 
87
        // image size
88
        input [15:0] Thgate, Tvgate; // horizontal/vertical gate
89
        // image data
90
        input [23:0] idat;           // image data input
91
        input        idat_wreq;      // image data write request
92
 
93
        // cursor data
94
        input [31:0] cursor_xy;      // cursor (x,y)
95
        input        cursor_en;      // cursor enable (on/off)
96 33 rherveille
        input        cursor_res;     // cursor resolution (32x32 or 64x64 pixels)
97
        input [ 8:0] cursor_wadr;    // cursor buffer write address
98
        input [31:0] cursor_wdat;    // cursor buffer write data
99
        input        cursor_we;      // cursor buffer write enable
100 31 rherveille
 
101 33 rherveille
        // color registers interface
102
        output [ 3:0] cc_adr_o;      // cursor color registers address
103
        reg  [ 3:0] cc_adr_o;
104
        input  [15:0] cc_dat_i;      // cursor color registers data
105
 
106 31 rherveille
        // rgb-fifo connections
107
        output        rgb_fifo_wreq; // rgb-out write request
108
        reg        rgb_fifo_wreq;
109
        output [23:0] rgb;           // rgb data output
110
        reg [23:0] rgb;
111
 
112
        //
113
        // variable declarations
114
        //
115 33 rherveille
        reg         dcursor_en, ddcursor_en, dddcursor_en;
116 31 rherveille
        reg  [15:0] xcnt, ycnt;
117
        wire        xdone, ydone;
118
        wire [15:0] cursor_x, cursor_y;
119 34 rherveille
        wire        cursor_isalpha;
120
        reg  [15:0] cdat, dcdat;
121
        wire [ 7:0] cursor_r, cursor_g, cursor_b, cursor_alpha;
122 31 rherveille
        reg         inbox_x, inbox_y;
123
        wire        inbox;
124 33 rherveille
        reg         dinbox, ddinbox, dddinbox;
125 31 rherveille
 
126 33 rherveille
        reg  [23:0] didat, ddidat, dddidat;
127
        reg         didat_wreq, ddidat_wreq;
128
        wire [31:0] cbuf_q;
129
        reg  [11:0] cbuf_ra;
130
        reg  [ 2:0] dcbuf_ra;
131
        wire [ 8:0] cbuf_a;
132
 
133
        reg         store1, store2;
134
 
135 31 rherveille
        //
136
        // module body
137
        //
138
 
139 33 rherveille
        //
140 31 rherveille
        // generate x-y counters
141
        always@(posedge clk)
142
                if(rst_i || xdone)
143
                        xcnt <= #1 16'h0;
144
                else if (idat_wreq)
145
                        xcnt <= #1 xcnt + 16'h1;
146
 
147
        assign xdone = (xcnt == Thgate) && idat_wreq;
148
 
149
        always@(posedge clk)
150
                if(rst_i || ydone)
151
                        ycnt <= #1 16'h0;
152
                else if (xdone)
153
                        ycnt <= #1 ycnt + 16'h1;
154
 
155 33 rherveille
        assign ydone = (ycnt == Tvgate) && xdone;
156 31 rherveille
 
157
 
158
        // decode cursor (x,y)
159
        assign cursor_x = cursor_xy[15: 0];
160
        assign cursor_y = cursor_xy[31:16];
161
 
162 33 rherveille
        //
163 31 rherveille
        // generate inbox signals
164
        always@(posedge clk)
165
                begin
166 33 rherveille
                        inbox_x <= #1 (xcnt >= cursor_x) && (xcnt < (cursor_x + (cursor_res ? 16'h7f : 16'h1f) ));
167
                        inbox_y <= #1 (ycnt >= cursor_y) && (ycnt < (cursor_y + (cursor_res ? 16'h7f : 16'h1f) ));
168 31 rherveille
                end
169
 
170
        assign inbox = inbox_x && inbox_y;
171
 
172 33 rherveille
        always@(posedge clk)
173
                dinbox <= #1 inbox;
174 31 rherveille
 
175 33 rherveille
        always@(posedge clk)
176
                if (didat_wreq)
177
                        ddinbox <= #1 dinbox;
178
 
179
        always@(posedge clk)
180
                dddinbox <= #1 ddinbox;
181
 
182
        //
183
        // generate cursor buffer address counter
184
        always@(posedge clk)
185
                if (!cursor_en || ydone)
186
                        cbuf_ra <= #1 12'h0;
187
                else if (inbox && idat_wreq)
188
                        cbuf_ra <= #1 cbuf_ra +12'h1;
189
 
190
        always@(posedge clk)
191
                dcbuf_ra <= #1 cbuf_ra[2:0];
192
 
193
        assign cbuf_a = cursor_we ? cursor_wadr : cursor_res ? cbuf_ra[11:3] : cbuf_ra[9:1];
194
 
195 31 rherveille
        // hookup local cursor memory (generic synchronous single port memory)
196
        // cursor memory should never be written to/read from at the same time
197 33 rherveille
        generic_spram #(9, 32) cbuf(
198 31 rherveille
                .clk(clk),
199
                .rst(1'b0),       // no reset
200
                .ce(1'b1),        // always enable memory
201
                .we(cursor_we),
202
                .oe(1'b1),        // always output data
203 33 rherveille
                .addr(cbuf_a),
204
                .di(cursor_wdat),
205
                .do(cbuf_q)
206 31 rherveille
        );
207
 
208 33 rherveille
        //
209
        // decode cursor data for 32x32x16bpp mode
210
        always@(posedge clk)
211
                if (didat_wreq)
212 34 rherveille
                        cdat <= #1 dcbuf_ra[0] ? cbuf_q[31:16] : cbuf_q[15:0];
213 31 rherveille
 
214 33 rherveille
        always@(posedge clk)
215 34 rherveille
                dcdat <= #1 cdat;
216 31 rherveille
 
217 33 rherveille
        //
218
        // decode cursor data for 64x64x4bpp mode
219 31 rherveille
 
220 33 rherveille
        // generate cursor-color address
221
        always@(posedge clk)
222
                if (didat_wreq)
223
                        case (dcbuf_ra)
224
                                3'b000: cc_adr_o <= cbuf_q[ 3: 0];
225
                                3'b001: cc_adr_o <= cbuf_q[ 7: 4];
226
                                3'b010: cc_adr_o <= cbuf_q[11: 8];
227
                                3'b011: cc_adr_o <= cbuf_q[15:12];
228
                                3'b100: cc_adr_o <= cbuf_q[19:16];
229
                                3'b101: cc_adr_o <= cbuf_q[23:20];
230
                                3'b110: cc_adr_o <= cbuf_q[27:24];
231
                                3'b111: cc_adr_o <= cbuf_q[31:28];
232
                        endcase
233 31 rherveille
 
234 33 rherveille
        //
235
        // generate cursor colors
236 34 rherveille
        assign cursor_isalpha =  cursor_res ? cc_dat_i[15]    : dcdat[15];
237
        assign cursor_alpha   =  cursor_res ? cc_dat_i[7:0]   : dcdat[7:0];
238
        assign cursor_r       = {cursor_res ? cc_dat_i[14:10] : dcdat[14:10], 3'h0};
239
        assign cursor_g       = {cursor_res ? cc_dat_i[ 9: 5] : dcdat[ 9: 5], 3'h0};
240
        assign cursor_b       = {cursor_res ? cc_dat_i[ 4: 0] : dcdat[ 4: 0], 3'h0};
241 33 rherveille
 
242
        //
243 31 rherveille
        // delay image data
244
        always@(posedge clk)
245 33 rherveille
                didat <= #1 idat;
246 31 rherveille
 
247 33 rherveille
        always@(posedge clk)
248
                if (didat_wreq)
249
                        ddidat <= #1 didat;
250 31 rherveille
 
251 33 rherveille
        always@(posedge clk)
252
                dddidat <= #1 ddidat;
253
 
254
        always@(posedge clk)
255
                begin
256
                        didat_wreq  <= #1 idat_wreq;
257
                        ddidat_wreq <= #1 didat_wreq;
258
                end
259
 
260
        //
261 31 rherveille
        // generate selection unit
262
        always@(posedge clk)
263
                dcursor_en <= #1 cursor_en;
264
 
265
        always@(posedge clk)
266 33 rherveille
                if (didat_wreq)
267
                        ddcursor_en <= #1 dcursor_en;
268 31 rherveille
 
269 33 rherveille
        always@(posedge clk)
270
                dddcursor_en <= #1 ddcursor_en;
271 31 rherveille
 
272 34 rherveille
        // Alpha blending:
273
        // rgb = (rgb1 * alhpa1) + (rgb2 * alpha2)
274
        // We generate an alpha mixer (alpha1 + alpha2 = 1)
275
        // rgb = (alpha1)(rgb1) + (1-alpha1)(rgb2)
276
        // We always mix to black (rgb2 = 0)
277
        // rgb = (alpha1)(rgb1)
278 33 rherveille
        always@(posedge clk)
279
                if (ddidat_wreq)
280
                        if (!dddcursor_en || !dddinbox)
281
                                rgb <= #1 dddidat;
282 34 rherveille
                        else if (cursor_isalpha)
283
                                `ifdef VGA_HWC_3D
284
                                        rgb <= #1 dddidat * cursor_alpha;
285
                                `else
286
                                        rgb <= #1 dddidat;
287
                                `endif
288 33 rherveille
                        else
289
                                rgb <= #1 {cursor_r, cursor_g, cursor_b};
290
 
291
        //
292 31 rherveille
        // generate write request signal
293
        always@(posedge clk)
294
                if (rst_i)
295 33 rherveille
                begin
296
                        store1 <= #1 1'b0;
297
                        store2 <= #1 1'b0;
298
                end
299
                else
300
                begin
301
                        store1 <= #1  didat_wreq           | store1;
302
                        store2 <= #1 (didat_wreq & store1) | store2;
303
                end
304 31 rherveille
 
305 33 rherveille
        // skip 2 idat_wreq signal, to keep in pace with rgb_fifo_full signal
306 31 rherveille
        always@(posedge clk)
307 33 rherveille
                rgb_fifo_wreq <= #1 ddidat_wreq & store2;
308 31 rherveille
 
309
endmodule

powered by: WebSVN 2.1.0

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