1 |
29 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
|
|
// \\__/ o\ (C) 2018-2020 Robert Finch, Waterloo
|
4 |
|
|
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
//
|
9 |
|
|
// BSD 3-Clause License
|
10 |
|
|
// Redistribution and use in source and binary forms, with or without
|
11 |
|
|
// modification, are permitted provided that the following conditions are met:
|
12 |
|
|
//
|
13 |
|
|
// 1. Redistributions of source code must retain the above copyright notice, this
|
14 |
|
|
// list of conditions and the following disclaimer.
|
15 |
|
|
//
|
16 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice,
|
17 |
|
|
// this list of conditions and the following disclaimer in the documentation
|
18 |
|
|
// and/or other materials provided with the distribution.
|
19 |
|
|
//
|
20 |
|
|
// 3. Neither the name of the copyright holder nor the names of its
|
21 |
|
|
// contributors may be used to endorse or promote products derived from
|
22 |
|
|
// this software without specific prior written permission.
|
23 |
|
|
//
|
24 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
25 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
26 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
27 |
|
|
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
28 |
|
|
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
29 |
|
|
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
30 |
|
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
31 |
|
|
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
32 |
|
|
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
33 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
34 |
|
|
//
|
35 |
|
|
// ============================================================================
|
36 |
|
|
//
|
37 |
|
|
module char_ram(clk_i, cs_i, we_i, adr_i, dat_i, dat_o, dot_clk_i, ce_i,
|
38 |
|
|
fontAddress_i, char_code_i, maxScanpix_i, maxscanline_i, scanline_i, bmp_o);
|
39 |
|
|
input clk_i;
|
40 |
|
|
input cs_i;
|
41 |
|
|
input we_i;
|
42 |
|
|
input [14:0] adr_i;
|
43 |
|
|
input [7:0] dat_i;
|
44 |
|
|
output reg [63:0] dat_o = 64'd0;
|
45 |
|
|
input dot_clk_i;
|
46 |
|
|
input ce_i;
|
47 |
|
|
input [15:0] fontAddress_i;
|
48 |
|
|
input [11:0] char_code_i;
|
49 |
|
|
input [5:0] maxScanpix_i;
|
50 |
|
|
input [5:0] maxscanline_i;
|
51 |
|
|
input [5:0] scanline_i;
|
52 |
|
|
output reg [63:0] bmp_o;
|
53 |
|
|
|
54 |
|
|
(* ram_style="block" *)
|
55 |
|
|
reg [7:0] mem [0:32767];
|
56 |
|
|
reg [14:0] radr;
|
57 |
|
|
reg [14:0] rcc, rcc0, rcc1;
|
58 |
|
|
reg [2:0] rcc200, rcc201, rcc202;
|
59 |
|
|
reg [63:0] dat1;
|
60 |
|
|
reg [63:0] bmp1;
|
61 |
|
|
reg [3:0] bndx, b2ndx;
|
62 |
|
|
reg [7:0] bmp [0:7];
|
63 |
|
|
reg [63:0] buf2;
|
64 |
|
|
|
65 |
|
|
initial begin
|
66 |
|
|
`include "d:\\cores2020\\rtf64\\v2\\rtl\\verilog\\soc\\memory\\char_bitmaps_12x18.v";
|
67 |
|
|
end
|
68 |
|
|
|
69 |
|
|
wire pe_cs;
|
70 |
|
|
edge_det ued1 (.rst(1'b0), .clk(clk_i), .ce(1'b1), .i(cs_i), .pe(pe_cs), .ne(), .ee());
|
71 |
|
|
|
72 |
|
|
always @(posedge clk_i)
|
73 |
|
|
if (cs_i & we_i)
|
74 |
|
|
mem[adr_i] <= dat_i;
|
75 |
|
|
|
76 |
|
|
// Char code is already delated two clocks relative to ce
|
77 |
|
|
// Assume that characters are always going to be at least four clocks wide.
|
78 |
|
|
// Clock #0
|
79 |
|
|
always @(posedge dot_clk_i)
|
80 |
|
|
if (ce_i)
|
81 |
|
|
rcc <= char_code_i*maxscanline_i+scanline_i;
|
82 |
|
|
// Clock #1
|
83 |
|
|
always @(posedge dot_clk_i)
|
84 |
|
|
casez(maxScanpix_i[5:3])
|
85 |
|
|
3'b1??: rcc0 <= {rcc,3'b0};
|
86 |
|
|
// 3'b110: rcc0 <= {rcc,2'b0} + {rcc,1'b0};
|
87 |
|
|
// 3'b101: rcc0 <= {rcc,2'b0} + rcc;
|
88 |
|
|
3'b01?: rcc0 <= {rcc,2'b0};
|
89 |
|
|
// 3'b010: rcc0 <= {rcc,1'b0} + rcc;
|
90 |
|
|
3'b001: rcc0 <= {rcc,1'b0};
|
91 |
|
|
3'b000: rcc0 <= rcc;
|
92 |
|
|
endcase
|
93 |
|
|
// Clock #2
|
94 |
|
|
always @(posedge dot_clk_i)
|
95 |
|
|
if (ce_i) begin
|
96 |
|
|
rcc1 <= {fontAddress_i[15:3],3'b0}+rcc0;
|
97 |
|
|
casez(maxScanpix_i[5:3])
|
98 |
|
|
3'b1??: bndx <= 4'd7;
|
99 |
|
|
3'b01?: bndx <= 4'd3;
|
100 |
|
|
3'b001: bndx <= 4'd1;
|
101 |
|
|
3'b000: bndx <= 4'd0;
|
102 |
|
|
endcase
|
103 |
|
|
end
|
104 |
|
|
else begin
|
105 |
|
|
if (~bndx[3]) begin
|
106 |
|
|
bmp[bndx[2:0]] <= mem[rcc1];
|
107 |
|
|
rcc1 <= rcc1 + 1'd1;
|
108 |
|
|
bndx <= bndx - 1'd1;
|
109 |
|
|
end
|
110 |
|
|
end
|
111 |
|
|
always @(posedge dot_clk_i)
|
112 |
|
|
if (ce_i)
|
113 |
|
|
bmp_o <= {bmp[7],bmp[6],bmp[5],bmp[4],bmp[3],bmp[2],bmp[1],bmp[0]};
|
114 |
|
|
|
115 |
|
|
endmodule
|