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

Subversion Repositories m1_core

[/] [m1_core/] [trunk/] [hdl/] [rtl/] [wb_text_vga/] [wb_text_vga.v] - Blame information for rev 59

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

Line No. Rev Author Line
1 34 fafa1971
/*
2
 * Text-only VGA Controller with Wishbone interface
3
 *
4
 * Includes a small Video RAM containing the chars to be shown on screen.
5
 * Handles the VGA display in common VGA resolution (640x480 @ 60 Hz).
6
 * Fonts are designed with 8x8 resolution and then spread over 16x16 pixels
7
 * in order to save memory, thus obtaining 40 columns and 30 rows.
8
 * It should use only 2 Block RAMs on Xilinx devices (2KB+2KB), one ROM to
9
 * store the bitmap for each of the 256 chars of the ASCII table and a Video
10
 * RAM to store the ASCII code for each of the 1200 chars on screen.
11
 * How it works: just write a byte using the Wishbone slave interface and it
12
 * will show on screen in black & white.
13
 */
14
 
15
`define HSYNC_COUNTER_MAX 1600
16
`define HSYNC_PULSE_START 1312
17
`define HSYNC_PULSE_STOP  1504
18
 
19
`define VSYNC_COUNTER_MAX 521
20
`define VSYNC_PULSE_START 490
21
`define VSYNC_PULSE_STOP  492
22
 
23
module wb_text_vga (
24
 
25
    // System
26
    input sys_clock_i,
27
    input sys_reset_i,
28
 
29
    // Wishbone slave interface
30
    input wb_cyc_i,
31
    input wb_stb_i,
32
    input wb_we_i,
33
    input[3:0] wb_sel_i,
34
    input[31:0] wb_adr_i,
35
    input[31:0] wb_dat_i,
36
    output wb_ack_o,
37
    output[31:0] wb_dat_o,
38
 
39
    // VGA Port
40
    output vga_rgb_r_o,
41
    output vga_rgb_g_o,
42
    output vga_rgb_b_o,
43
    output reg vga_hsync_o,
44
    output reg vga_vsync_o
45
 
46
  );
47
 
48
  /*
49
   * Registers
50
   */
51
 
52
  // Current position of the cursor
53
  reg[5:0] text_col;
54
  reg[4:0] text_row;
55
 
56
  // Horizontal and vertical counters
57
  reg[10:0] hcounter;
58
  reg[9:0] vcounter;
59
 
60
  /*
61
   * Wires
62
   */
63
 
64
  // Coordinates of the pixel being drawn
65
  wire[9:0] pixel_x;
66
  wire[8:0] pixel_y;
67
 
68
  // Video RAM port 1 wires (read/write)
69
  wire ram_write1;
70
  wire[10:0] ram_address1;
71
  wire[7:0] ram_wdata1;
72
  wire[7:0] ram_rdata1;
73
 
74
  // Video RAM port 2 wires (read-only)
75
  wire[10:0] ram_address2;
76
  wire[7:0] ram_rdata2;
77
 
78
  // Fontmap ROM wires
79
  wire rom_enable;
80
  wire[10:0] rom_address;
81
  wire[7:0] rom_data;
82
 
83
  /*
84
   * Module instances
85
   */
86
 
87
  // Video RAM instance
88
  video_ram video_ram_0 (
89
 
90
    // System
91
    .sys_clock_i(sys_clock_i),
92
 
93
    // Port 1 (read/write)
94
    .write1_i(ram_write1),
95
    .address1_i(ram_address1),
96
    .data1_i(ram_wdata1),
97
    .data1_o(ram_rdata1),
98
 
99
    // Port 2 (read-only)
100
    .address2_i(ram_address2),
101
    .data2_o(ram_rdata2)
102
  );
103
 
104
  // Fontmap ROM instance
105
  fontmap_rom fontmap_rom_0 (
106
    .sys_clock_i(sys_clock_i),
107
    .read_i(rom_enable),
108
    .address_i(rom_address),
109
    .data_o(rom_data)
110
  );
111
 
112
  /*
113
   * Combinational logic
114
   */
115
 
116
  // Wishbone request is always served immediately
117
  assign wb_ack_o = (wb_cyc_i && wb_stb_i);
118
 
119
  // No Wishbone read allowed
120
  assign wb_dat_o = 32'h00000000;
121
 
122
  // Wishbone writes go directly to Video RAM
123
  assign ram_write1 = (wb_cyc_i && wb_stb_i && wb_we_i);
124
  assign ram_wdata1 = wb_dat_i[7:0];
125
 
126
  // The address of the write to Video RAM is the coordinate of the next char
127
  assign ram_address1 = { text_row , text_col };
128
 
129
  // The second port of the Video RAM is used to retrieve the ASCII code of the char to be shown on screen
130
  assign ram_address2 = { vcounter[9:5] , hcounter[10:5] };
131
 
132
  // Read continuously from ROM
133
  assign rom_enable = 1;
134
 
135
  // The address of the read from Fontmap ROM is the ASCII code concatenated with the number of line in the char
136
  assign rom_address = { ram_rdata2 , vcounter[4:2] };
137
 
138
  // Now draw the pixel in black & white
139
  assign vga_rgb_r_o = rom_data[8-hcounter[4:2]];
140
  assign vga_rgb_g_o = rom_data[8-hcounter[4:2]];
141
  assign vga_rgb_b_o = rom_data[8-hcounter[4:2]];
142
 
143
  /*
144
   * Sequential logic
145
   */
146
 
147
  always @(posedge sys_clock_i) begin
148
 
149
    if(sys_reset_i) begin
150
 
151
      // Reset registers
152
      text_row <= 0;
153
      text_col <= 0;
154
      hcounter <= 0;
155
      vcounter <= 0;
156
 
157
      // Clear outputs
158
      vga_hsync_o <= 1;
159
      vga_vsync_o <= 1;
160
 
161
    end else begin
162
 
163
      // Update counters and handle upper bounds
164
      if (hcounter == (`HSYNC_COUNTER_MAX-1) ) begin
165
        hcounter <= 0;
166
        if (vcounter == (`VSYNC_COUNTER_MAX-1) ) begin
167
          vcounter <= 0;
168
        end else begin
169
          vcounter <= vcounter + 1;
170
        end
171
      end else begin
172
        hcounter <= hcounter + 1;
173
      end
174
 
175
      // Drive sync outputs 
176
      if(hcounter>=`HSYNC_PULSE_START && hcounter<`HSYNC_PULSE_STOP)
177
        vga_hsync_o <= 0;
178
      else
179
        vga_hsync_o <= 1;
180
      if(vcounter>=`VSYNC_PULSE_START && vcounter<`VSYNC_PULSE_STOP)
181
        vga_vsync_o <= 0;
182
      else
183
        vga_vsync_o <= 1;
184
 
185
      // Handle the writing from the Wishbone bus
186
      if(wb_cyc_i && wb_stb_i && wb_we_i) begin
187
 
188
        // Handle cursor position including New Line Feed
189
        if(text_col==39 || wb_dat_i[7:0]==8'h0A) begin
190
          text_col <= 0;
191
          if(text_row==29) begin
192
            text_row <= 0;
193
          end else begin
194
            text_row <= text_row + 1;
195
          end
196
        end else begin
197
          text_col <= text_col + 1;
198
        end
199
 
200
        // During simulation print char to stdout
201
        $display("WB-TEXT: Print char '%c'", wb_dat_i[7:0]);
202
 
203
      end
204
    end
205
  end
206
 
207
endmodule

powered by: WebSVN 2.1.0

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