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

Subversion Repositories vg_z80_sbc

[/] [vg_z80_sbc/] [trunk/] [rtl/] [wb_vga.v] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hharte
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  wb_vga.v - Wishbone wrapper and Video/Font RAM.             ////
4
////                                                              ////
5
////  This file is part of the Text-Mode VGA Controller Project   ////
6
////  http://www.opencores.org/projects/                          ////
7
////                                                              ////
8
////  Author:                                                     ////
9
////      - Howard M. Harte (hharte@opencores.org)                ////
10
////                                                              ////
11
//////////////////////////////////////////////////////////////////////
12
////                                                              ////
13
//// Copyright (C) 2008 Howard M. Harte                           ////
14
////                                                              ////
15
//// This source file may be used and distributed without         ////
16
//// restriction provided that this copyright statement is not    ////
17
//// removed from the file and that any derivative work contains  ////
18
//// the original copyright notice and the associated disclaimer. ////
19
////                                                              ////
20
//// This source file is free software; you can redistribute it   ////
21
//// and/or modify it under the terms of the GNU Lesser General   ////
22
//// Public License as published by the Free Software Foundation; ////
23
//// either version 2.1 of the License, or (at your option) any   ////
24
//// later version.                                               ////
25
////                                                              ////
26
//// This source is distributed in the hope that it will be       ////
27
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
28
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
29
//// PURPOSE.  See the GNU Lesser General Public License for more ////
30
//// details.                                                     ////
31
////                                                              ////
32
//// You should have received a copy of the GNU Lesser General    ////
33
//// Public License along with this source; if not, download it   ////
34
//// from http://www.opencores.org/lgpl.shtml                     ////
35
////                                                              ////
36
//////////////////////////////////////////////////////////////////////
37
 
38
//////////////////////////////////////////////////////////////////////
39
////                                                              ////
40
//// This controller occupies 16K of address space:               ////
41
////                                                              ////
42
//// 0000-0FFF - Video RAM (Character storage)                    ////
43
//// 1000-1FFF - Font  RAM (Font storage)                         ////
44
//// 2000-2FFF - VGA Controller Registers                         ////
45
////             2000 - VGA OCTL                                  ////
46
////                    [7] - 1=Video enable / 0=disable          ////
47
////                    [6] - 1=Cursor enable / 0=disable         ////
48
////                    [5] - 1=Cursor blink / 0=solid            ////
49
////                    [4] - 1=Cursor Mode                       ////
50
////                    [2:0] - R/G/B Color Enables               ////
51
////             2001 - VGA OCTL2 (unused)                        ////
52
////             2002 - VGA OCRX Cursor X Position                ////
53
////             2003 - VGA OCRY Cursor Y Position                ////
54
//// 3000-3FFF - Unused                                           ////
55
////                                                              ////
56
//////////////////////////////////////////////////////////////////////
57
 
58
module wb_vga(
59
    // VGA Interface
60
    clk_i, clk_50mhz_i, nrst_i, wb_adr_i, wb_dat_o, wb_dat_i, wb_sel_i, wb_we_i,
61
    wb_stb_i, wb_cyc_i, wb_ack_o,
62
    vga_hsync_o, vga_vsync_o, vga_r_o, vga_g_o, vga_b_o
63
);
64
 
65
    parameter font_file_name = "fwii_8x10.ram";     // Font filename (must contain exactly 4K of data)
66
    parameter font_height = 10;    // Number of pixels in font height
67
    parameter text_height = 2; // 1=80x48, 2=80x24
68
 
69
    //
70
    // Wishbone Wrapper for Text-Mode VGA Controller
71
    //
72
    input            clk_i;
73
    input            clk_50mhz_i;
74
    input            nrst_i;
75
    input     [13:0] wb_adr_i;
76
    output    [31:0] wb_dat_o;
77
    input     [31:0] wb_dat_i;
78
    input      [3:0] wb_sel_i;
79
    input            wb_we_i;
80
    input            wb_stb_i;
81
    input            wb_cyc_i;
82
    output  reg      wb_ack_o;
83
    output           vga_hsync_o;
84
    output           vga_vsync_o;
85
    output           vga_r_o;
86
    output           vga_g_o;
87
    output           vga_b_o;
88
 
89
    wire     [7:0]   vga_dat;
90
    wire    [11:0]   vga_adr;
91
 
92
    reg     [7:0]    vga_regs[0:3];
93
 
94
    wire     [7:0]   octl = vga_regs[0]; // 7=vga_en, 6=cursor_en, 2:0=color
95
    wire     [7:0]   octl2 = vga_regs[1]; // unused for now
96
    wire     [7:0]   ocrx = vga_regs[2];
97
    wire     [7:0]   ocry = vga_regs[3];
98
 
99
    wire    [11:0]   font_a;
100
    wire     [7:0]   font_d;
101
 
102
    wire    [1:0]    adr_low;
103
    wire    [7:0]    dpram_dat_o;
104
    wire    [7:0]    dpram_dat_i;
105
 
106
    reg              clk25mhz;
107
    wire             vga_clk = clk25mhz;
108
 
109
    wire             video_ram_acc = wb_adr_i[13:12] == 2'b00;
110
    wire             font_ram_acc = wb_adr_i[13:12] == 2'b01;
111
    wire             vga_regs_acc = wb_adr_i[13:12] == 2'b10;
112
 
113
    wire    [7:0]    font_dat_o;
114
    wire    [7:0]    reg_dat_o;
115
 
116
    //
117
    // generate wishbone register bank writes
118
    wire wb_acc = wb_cyc_i & wb_stb_i;    // WISHBONE access
119
    wire wb_wr  = wb_acc & wb_we_i;       // WISHBONE write access
120
    wire wb_rd  = wb_acc & ~wb_we_i;      // WISHBONE read access
121
    wire vga_ram_wr = wb_wr & video_ram_acc;
122
    wire font_ram_wr = wb_wr & font_ram_acc;
123
    wire vga_reg_wr = wb_wr & vga_regs_acc;
124
 
125
    // generate ack_o
126
    always @(posedge clk_i)
127
        wb_ack_o <= #1 wb_acc & !wb_ack_o;
128
 
129
    assign adr_low = wb_sel_i == 4'b0001 ? 2'b00 : wb_sel_i == 4'b0010 ? 2'b01 : wb_sel_i == 4'b0100 ? 2'b10 : 2'b11;
130
    assign wb_dat_o = video_ram_acc ? {dpram_dat_o, dpram_dat_o, dpram_dat_o, dpram_dat_o} :
131
                       font_ram_acc ? {font_dat_o, font_dat_o, font_dat_o, font_dat_o} :
132
                       {reg_dat_o, reg_dat_o, reg_dat_o, reg_dat_o};
133
    assign dpram_dat_i = wb_sel_i == 4'b0001 ? wb_dat_i[7:0] : wb_sel_i == 4'b0010 ? wb_dat_i[15:8] : wb_sel_i == 4'b0100 ? wb_dat_i[23:16] : wb_dat_i[31:24];
134
 
135
    always @(posedge clk_i or negedge nrst_i)
136
        if (~nrst_i)                // reset registers
137
            begin
138
                vga_regs[0] <= 8'b10110111; // 7=vga_en, 6=cursor_en, 2:0=color
139
                vga_regs[1] <= 8'b00000000; // 0xA5
140
                vga_regs[2] <= 8'b00000000;
141
                vga_regs[3] <= 8'b00000000;
142
            end
143
        else if(vga_reg_wr)          // wishbone write cycle
144
            vga_regs[adr_low] <= dpram_dat_i;
145
 
146
        assign reg_dat_o = vga_regs[adr_low];
147
 
148
// Instantiate the VGA module
149
vga80x40    # (
150
    .font_height(font_height),
151
    .text_height(text_height))
152
vga_controller (
153
    .reset(~nrst_i),
154
    .clk25MHz(vga_clk),
155
    .TEXT_A(vga_adr),
156
    .TEXT_D(vga_dat),
157
    .FONT_A(font_a),
158
    .FONT_D(font_d),
159
    .ocrx(ocrx),
160
    .ocry(ocry),
161
    .octl(octl),
162
    .R(vga_r_o),
163
    .G(vga_g_o),
164
    .B(vga_b_o),
165
    .hsync(vga_hsync_o),
166
    .vsync(vga_vsync_o)
167
    );
168
 
169
// Instantiate the Video RAM (4K)
170
// synthesis attribute ram_style of video_ram is block
171
vga_dpram #(
172
    .mem_file_name("none"),
173
    .adr_width(12),
174
    .dat_width(8)
175
) video_ram (
176
    .clk1(clk_i),
177
    .clk2(vga_clk),
178
    //
179
    .adr0({wb_adr_i[11:2], adr_low}),
180
    .dout0(dpram_dat_o),
181
    .din0(dpram_dat_i),
182
    .we0(vga_ram_wr),
183
    //
184
    .adr1(vga_adr),
185
    .dout1(vga_dat),
186
    .din1(8'b0),
187
    .we1(1'b0)
188
);
189
 
190
// Instantiate the Font RAM (4K, initialized with font data)
191
// synthesis attribute ram_style of font_ram is block
192
vga_dpram #(
193
    .mem_file_name(font_file_name),
194
    .adr_width(12),
195
    .dat_width(8)
196
) font_ram (
197
    .clk1(clk_i),
198
    .clk2(vga_clk),
199
    //
200
    .adr0({wb_adr_i[11:2], adr_low}  ),
201
    .dout0(font_dat_o),
202
    .din0(dpram_dat_i),
203
    .we0(font_ram_wr),
204
    //
205
    .adr1(font_a),
206
    .dout1(font_d),
207
    .din1(8'b0),
208
    .we1(1'b0)
209
);
210
 
211
// Generate 25MHz Pixel Clock
212
always @(posedge clk_50mhz_i or negedge nrst_i)
213
    if (~nrst_i)
214
        begin
215
            clk25mhz <= 1'b0;
216
        end else begin
217
            clk25mhz <= !clk25mhz;
218
        end
219
 
220
endmodule
221
 

powered by: WebSVN 2.1.0

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