OpenCores
URL https://opencores.org/ocsvn/6809_6309_compatible_core/6809_6309_compatible_core/trunk

Subversion Repositories 6809_6309_compatible_core

[/] [6809_6309_compatible_core/] [trunk/] [syn/] [lattice/] [vgatext.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 ale500
 
2
module vgatext(
3
        input wire CLK,
4
        input wire RESET,
5
        output wire HSYNC,
6
        output wire VSYNC,
7
        output wire RED,
8
        output wire GREEN,
9
        output wire BLUE,
10
        input wire CPU_CLK,
11
        input wire [11:0] CPU_ADDR,
12
        input wire CPU_OE_EN,
13
        input wire CPU_WR_EN,
14
        input wire [7:0] CPU_DATA_O,
15
        output wire [7:0] CPU_DATA_I
16
        );
17
`ifdef CLK25
18
`define LINE_LENGTH    11'd831
19
`define HSYNC_START    11'd704+11'd64+11'd32
20
`define HVISIBLE_START 11'd16+11'd64
21
`define HVISIBLE_END   11'd656+11'd64
22
`define VVISIBLE_START 11'd10
23
`define VVISIBLE_END   11'd490
24
`define FRAME_END      11'd525
25
`define VSYNC_START    11'd524
26
`else
27
/* For 40 MHz clk 800x600 60 Hz */
28
`define LINE_LENGTH    11'd1055
29
`define HSYNC_START    11'd840+11'd88
30
`define HVISIBLE_START 11'd40
31
`define HVISIBLE_END   11'd840
32
`define VVISIBLE_START 11'd16
33
`define VVISIBLE_END   11'd616
34
`define FRAME_END      11'd627
35
`define VSYNC_START    11'd624
36
`endif
37
reg [10:0] hsync_cnt, vsync_cnt;
38
reg [3:0] redr, greenr, bluer;
39
reg hsyncr, vsyncr;
40
 
41
assign HSYNC = hsyncr;
42
assign VSYNC = vsyncr;
43
reg visible;
44
 
45
reg [5:0] blink_cnt;
46
 
47
assign RED = visible ? redr[0]:0;
48
assign GREEN = visible ? greenr[0]:0;
49
assign BLUE = visible ? bluer[0]:0;
50
 
51
always @(posedge CLK)
52
        begin
53
                if (RESET == 1'b1)
54
                        begin
55
                                hsync_cnt <= 11'h0;
56
                                vsync_cnt <= 11'h0;
57
                        end
58
                else
59
                        begin
60
                                if (hsync_cnt == `LINE_LENGTH) // end of line
61
                                        begin
62
                                                hsync_cnt <= 0;
63
                                                hsyncr <= 1'b1;
64
                                                if (vsync_cnt == `FRAME_END)
65
                                                        begin
66
                                                                vsync_cnt <= 11'd0;
67
                                                                blink_cnt <= blink_cnt + 6'h1; // blinking cursor counter
68
                                                        end
69
                                                else
70
                                                        vsync_cnt <= vsync_cnt + 11'd1;
71
                                        end
72
                                else
73
                                        hsync_cnt <= hsync_cnt + 11'd1;
74
                        end
75
                hsyncr <= hsync_cnt >= `HSYNC_START ? 0:1;
76
                vsyncr <= vsync_cnt >= `VSYNC_START ? 0:1;
77
                visible <= (hsync_cnt >= `HVISIBLE_START) && (hsync_cnt < `HVISIBLE_END) && (vsync_cnt >= `VVISIBLE_START) && (vsync_cnt < `VVISIBLE_END);
78
        end
79
 
80
wire enable = (hsync_cnt >= `HVISIBLE_START-11'd8) && (hsync_cnt < `HVISIBLE_END) && (vsync_cnt >= `VVISIBLE_START) && (vsync_cnt < `VVISIBLE_END);
81
reg [6:0] x_cnt, y_cnt, cur_x, cur_y;
82
reg [3:0] line_cnt;
83
reg [7:0] chars_data, font_data, tshift, shift;
84
wire [7:0] font_bus, chars_bus;
85
 
86
wire [11:0] yptr;
87
assign yptr = { y_cnt[5:0], 6'h0 } + { y_cnt[5:0], 5'h0 } + { y_cnt[5:0], 2'h0 } + { 4'h0, x_cnt };
88
 
89
fontrom font(.Address({ chars_data, line_cnt }), .OutClock(CLK), .OutClockEn(1'b1), .Reset(1'b0), .Q(font_bus));
90
 
91
textmem4k chars(
92
//.WrAddress(WrAddr), .RdAddress(yptr), .Data(WrData), .WE(WrEn), .RdClock(CLK), .RdClockEn(1'b1), 
93
//    .Reset(1'b0), .WrClock(WrClk), .WrClockEn(1'b1), .Q(chars_bus));
94
 
95
        .DataInA(),
96
        .AddressA(yptr),
97
        .ClockA(CLK),
98
        .ClockEnA(1'b1),
99
        .WrA(1'b0),
100
        .ResetA(1'b0),
101
        .QA(chars_bus),
102
 
103
        .DataInB(CPU_DATA_O),
104
        .AddressB(CPU_ADDR),
105
        .ClockB(CPU_CLK),
106
    .ClockEnB(CPU_WR_EN | CPU_OE_EN),
107
        .WrB(CPU_WR_EN),
108
        .ResetB(1'b0),
109
        .QB(CPU_DATA_I)
110
        );
111
 
112
 
113
always @(posedge CLK) // read memory
114
        begin
115
                chars_data <= chars_bus;//[{ y_cnt[4:0], x_cnt }];
116
                font_data <= font_bus;
117
        end
118
 
119
always @(posedge CLK)
120
        begin
121
                if (hsync_cnt == 0)
122
                        begin
123
                                x_cnt <= 0;
124
                                cur_x <= 3; // not needed
125
                        end
126
                if (vsync_cnt == 0)
127
                        begin
128
                                y_cnt <= 0;
129
                                line_cnt <= 0;
130
                                cur_y <= 1;
131
                        end
132
                if ((hsync_cnt == `LINE_LENGTH) && (vsync_cnt >= `VVISIBLE_START))
133
                        begin
134
                                $display(" ");
135
                                line_cnt <= line_cnt + 1;
136
                                if (line_cnt == 4'hf)
137
                                        y_cnt <= y_cnt + 1;
138
                        end
139
                if (enable)
140
                        begin
141
 
142
                                case (hsync_cnt[2:0]) // start of group of 8 consecutive pixels
143
                                        0: // read new char/color
144
                                                begin
145
                                                         shift <= shift << 1;
146
                                                    x_cnt <= x_cnt + 1;
147
                                                end
148
                                        1: // reads font
149
                                                shift <= shift << 1;
150
                                        2: // load font data into shift register
151
                                                begin
152
                                                        shift <= shift << 1;
153
                                                        tshift <= font_data;
154
                                                end
155
                                        3, 4, 5, 6:
156
                                                shift <= shift << 1;
157
                                        7: // uses read shift register
158
                                                begin
159
                                                        shift <= tshift;
160
 
161
                                                end
162
                                endcase
163
                                if ((cur_x == x_cnt) && (cur_y == y_cnt) && (line_cnt > 4'd13) && blink_cnt[5])
164
                                        begin
165
                                                redr <= 4'hf;
166
                                                greenr <= 4'hf;
167
                                                bluer <= 4'hf;
168
                                                $write("!");
169
                                        end
170
                                else
171
                                        begin
172
                                                redr <= shift[7] ? 4'hf:4'h0;
173
                                                greenr <= shift[7] ? 4'hf:4'h0;
174
                                                bluer <= shift[7] ? 4'hf:4'h0;
175
                                                $write("%c", shift[7] ? 33:32);
176
                                        end
177
                        end
178
                else
179
                        begin
180
                                redr <= 4'h0;
181
                                greenr <= 4'h0;
182
                                bluer <= 4'h0;
183
                        end
184
        end
185
initial
186
        begin
187
                redr = 0;
188
                greenr = 0;
189
                bluer = 0;
190
                vsync_cnt = 0;
191
                hsync_cnt = 0;
192
        end
193
endmodule

powered by: WebSVN 2.1.0

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