This commit is contained in:
Zack Buhman 2024-08-15 03:14:44 -05:00
parent 07a460e0f0
commit a498132c0a
10 changed files with 77738 additions and 21 deletions

View File

@ -2,6 +2,7 @@ set -eux
yosys <<EOF yosys <<EOF
read_verilog vga_spg.v read_verilog vga_spg.v
read_verilog vga_mem.v
read_verilog vga_fb.v read_verilog vga_fb.v
read_verilog vga_top.v read_verilog vga_top.v
synth_gatemate -top vga_top -nomx8 -vlog net/synth.v synth_gatemate -top vga_top -nomx8 -vlog net/synth.v

17
gen_vga_mem.py Normal file
View File

@ -0,0 +1,17 @@
with open('parrot.data', 'rb') as f:
buf = f.read()
assert len(buf) == 320 * 240 * 3, len(buf)
with open('vga_ram.hex', 'w') as f:
for i in range(320 * 240):
r = buf[i * 3 + 0]
g = buf[i * 3 + 1]
b = buf[i * 3 + 2]
r4 = r >> 4
g4 = g >> 4
b4 = b >> 4
f.write(f'{r4:x}{g4:x}{b4:x}')
f.write('\n')

837
parrot.data Normal file

File diff suppressed because one or more lines are too long

BIN
parrot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 KiB

View File

@ -1,4 +1,4 @@
set -eux set -eux
iverilog -o bin/vga_tb vga_spg.v vga_fb.v vga_tb.v iverilog -o bin/vga_tb vga_spg.v vga_fb.v vga_tb.v vga_mem.v
vvp bin/vga_tb vvp bin/vga_tb

View File

@ -1,16 +1,16 @@
module vga_fb module vga_fb
(input wire clk, (input wire clk,
input wire rst, input wire rst,
output reg [3:0] red, output reg [3:0] red,
output reg [3:0] green, output reg [3:0] green,
output reg [3:0] blue, output reg [3:0] blue,
output h_sync, output reg h_sync,
output v_sync); output reg v_sync,
output wire [9:0] h_count,
output wire [9:0] v_count,
wire [9:0] h_count; output wire display,
wire [9:0] v_count; output reg [18:0] addr
wire display; );
wire h_sync1; wire h_sync1;
wire v_sync1; wire v_sync1;
@ -23,13 +23,43 @@ module vga_fb
.v_sync(v_sync1), .v_sync(v_sync1),
.display(display)); .display(display));
//reg [18:0] addr;
reg clk2;
always @(posedge clk) begin
if (rst)
clk2 <= 1'b0;
else
clk2 <= ~clk2;
if (rst || v_sync1) begin
addr <= 0;
end else if (display) begin
if (clk2)
if (addr < 76799)
addr <= addr + 1;
else
addr <= 0;
end
end
wire read = 1'b1;
wire [11:0] rdata;
vga_mem mem(.clk(clk),
.read(read),
.addr(addr),
.rdata(rdata));
always @(posedge clk) begin always @(posedge clk) begin
h_sync <= !h_sync1; h_sync <= !h_sync1;
v_sync <= !v_sync1; v_sync <= !v_sync1;
if (display) begin if (display) begin
red <= v_count[8:5]; red <= rdata[11:8];
blue <= h_count[8:5]; green <= rdata[7:4];
blue <= rdata[3:0];
end else begin end else begin
red <= 4'd0; red <= 4'd0;
green <= 4'd0; green <= 4'd0;

18
vga_mem.v Normal file
View File

@ -0,0 +1,18 @@
module vga_mem
(input wire clk,
input wire read,
input wire [18:0] addr,
output reg [11:0] rdata
);
reg [11:0] mem [0:76799];
initial
$readmemh("vga_ram.hex", mem);
always @(posedge clk) begin
if (read) begin
rdata <= mem[addr];
end
end
endmodule

76800
vga_ram.hex Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
module vga_spg module vga_spg
(input wire clk, (input wire clk,
input wire rst, input wire rst,
output reg [9:0] h_count, output reg [9:0] h_count,
output reg [9:0] v_count, output reg [9:0] v_count,
output reg h_sync, output reg h_sync,
output reg v_sync, output reg v_sync,
output wire display output reg display
); );
localparam h_visible = 640; localparam h_visible = 640;
@ -86,6 +86,7 @@ module vga_spg
end end
// display // display
//assign display = h_count < h_visible && v_count < v_visible;
always @(posedge clk) begin always @(posedge clk) begin
display <= h_count < h_visible && v_count < v_visible; display <= h_count < h_visible && v_count < v_visible;
end end

View File

@ -19,6 +19,10 @@ module vga_tb;
wire [3:0] blue; wire [3:0] blue;
wire h_sync; wire h_sync;
wire v_sync; wire v_sync;
wire [9:0] h_count;
wire [9:0] v_count;
wire display;
wire [18:0] addr;
vga_fb fb(clk, vga_fb fb(clk,
rst, rst,
@ -26,6 +30,15 @@ module vga_tb;
green, green,
blue, blue,
h_sync, h_sync,
v_sync); v_sync,
h_count,
v_count,
display,
addr);
always @(negedge clk) begin
if (!rst && display)
$display("%h %h %h %h %h %h", addr, h_count, v_count, red, green, blue);
end
endmodule endmodule