textdisplay.sv (1475B)
1 // Copyright 2014 Brian Swetland <swetland@frotz.net> 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 `timescale 1ns / 1ps 16 17 module textdisplay( 18 input pixclk, 19 input [10:0]xpixel, 20 input [10:0]ypixel, 21 output reg pixel, 22 23 input bufclk, 24 input [11:0]bufaddr, 25 input [7:0]bufdata, 26 input bufwe 27 ); 28 29 wire [7:0]cdata; 30 wire [9:0]caddr; 31 32 wire [7:0]bdata; 33 wire [11:0]baddr; 34 35 assign baddr = { ypixel[9:4], xpixel[9:4] }; 36 assign caddr = { bdata[6:0], ypixel[3:1] }; 37 38 always_comb begin 39 case (xpixel[3:1]) 40 0: pixel = cdata[7]; 41 1: pixel = cdata[6]; 42 2: pixel = cdata[5]; 43 3: pixel = cdata[4]; 44 4: pixel = cdata[3]; 45 5: pixel = cdata[2]; 46 6: pixel = cdata[1]; 47 7: pixel = cdata[0]; 48 endcase 49 end 50 51 // text ram 52 reg [7:0]buffer[0:4095]; 53 always @(posedge bufclk) 54 if (bufwe) 55 buffer[bufaddr] <= bufdata; 56 assign bdata = buffer[baddr]; 57 58 // character pattern rom 59 reg [7:0]chardata[0:1023]; 60 initial $readmemh("chardata8x8.hex", chardata); 61 assign cdata = chardata[caddr]; 62 63 endmodule