1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-27 01:51:35 +00:00
8bitworkshop/presets/verilog/chardisplay.v

85 lines
1.8 KiB
Coq
Raw Normal View History

2018-02-03 20:20:56 +00:00
`include "hvsync_generator.v"
`include "digits10.v"
2018-06-01 17:33:37 +00:00
`include "ram.v"
2018-02-03 20:20:56 +00:00
2018-10-01 16:30:47 +00:00
/*
Displays a grid of digits on the CRT using a RAM module.
*/
module test_ram1_top(clk, reset, hsync, vsync, rgb);
2018-02-07 00:07:40 +00:00
input clk, reset;
output hsync, vsync;
output [2:0] rgb;
2018-02-03 20:20:56 +00:00
wire display_on;
wire [8:0] hpos;
wire [8:0] vpos;
wire [9:0] ram_addr;
wire [7:0] ram_read;
reg [7:0] ram_write;
reg ram_writeenable = 0;
// RAM to hold 32x32 array of bytes
2018-06-01 17:33:37 +00:00
RAM_sync ram(
2018-02-03 20:20:56 +00:00
.clk(clk),
.dout(ram_read),
.din(ram_write),
.addr(ram_addr),
.we(ram_writeenable)
);
hvsync_generator hvsync_gen(
.clk(clk),
.reset(reset),
.hsync(hsync),
.vsync(vsync),
.display_on(display_on),
.hpos(hpos),
.vpos(vpos)
);
wire [4:0] row = vpos[7:3]; // 5-bit row, vpos / 8
wire [4:0] col = hpos[7:3]; // 5-bit column, hpos / 8
wire [2:0] rom_yofs = vpos[2:0]; // scanline of cell
wire [4:0] rom_bits; // 5 pixels per scanline
2018-02-03 20:20:56 +00:00
wire [3:0] digit = ram_read[3:0]; // read digit from RAM
wire [2:0] xofs = hpos[2:0]; // which pixel to draw (0-7)
2018-02-03 20:20:56 +00:00
assign ram_addr = {row,col}; // 10-bit RAM address
// digits ROM
2018-02-03 20:20:56 +00:00
digits10_case numbers(
.digit(digit),
.yofs(rom_yofs),
.bits(rom_bits)
2018-02-03 20:20:56 +00:00
);
// extract bit from ROM output
2018-02-03 20:20:56 +00:00
wire r = display_on && 0;
wire g = display_on && rom_bits[~xofs];
2018-02-03 20:20:56 +00:00
wire b = display_on && 0;
assign rgb = {b,g,r};
// increment the current RAM cell
2018-02-03 20:20:56 +00:00
always @(posedge clk)
case (hpos[2:0])
// on 7th pixel of cell
6: begin
// increment RAM cell
ram_write <= (ram_read + 1);
// only enable write on last scanline of cell
ram_writeenable <= (vpos[2:0] == 7);
end
// on 8th pixel of cell
7: begin
// disable write
ram_writeenable <= 0;
end
endcase
2018-02-03 20:20:56 +00:00
endmodule