2018-11-11 11:10:40 +00:00
|
|
|
// FPGA VGA Graphics Part 1: Top Module (static squares)
|
|
|
|
// (C)2017-2018 Will Green - Licensed under the MIT License
|
|
|
|
// Heavily modified by Jens True
|
|
|
|
// Learn more at https://timetoexplore.net/blog/arty-fpga-vga-verilog-01
|
|
|
|
|
|
|
|
`default_nettype none
|
|
|
|
|
|
|
|
module vgasquare(
|
2018-11-11 17:55:56 +00:00
|
|
|
input wire PIXEL_CLK, // Pixel clock: 25Mhz (or 25.125MHz) for VGA
|
2018-11-11 11:10:40 +00:00
|
|
|
input wire RST_BTN, // reset button
|
|
|
|
input wire [9:0] box_x1,
|
|
|
|
input wire [9:0] box_x2,
|
|
|
|
input wire [8:0] box_y1,
|
|
|
|
input wire [8:0] box_y2,
|
2018-11-11 17:55:56 +00:00
|
|
|
input wire [5:0] box_color, //1 bit for each color Foreground and background
|
2018-11-19 19:59:35 +00:00
|
|
|
output wire VGA_HS, // horizontal sync output
|
|
|
|
output wire VGA_VS, // vertical sync output
|
2018-11-11 11:10:40 +00:00
|
|
|
output wire VGA_R, // 1-bit VGA red output
|
|
|
|
output wire VGA_G, // 1-bit VGA green output
|
|
|
|
output wire VGA_B // 1-bit VGA blue output
|
|
|
|
);
|
|
|
|
|
|
|
|
wire rst = ~RST_BTN; // reset is active low on AXI bus
|
|
|
|
|
|
|
|
wire [9:0] x; // current pixel x position: 10-bit value: 0-1023
|
|
|
|
wire [8:0] y; // current pixel y position: 9-bit value: 0-511
|
2018-11-26 14:12:41 +00:00
|
|
|
wire VGA_ACTIVE;
|
2018-11-11 11:10:40 +00:00
|
|
|
vga640x480 display (
|
2018-11-11 17:55:56 +00:00
|
|
|
.i_pix_stb(PIXEL_CLK),
|
2018-11-11 11:10:40 +00:00
|
|
|
.i_rst(rst),
|
2018-11-19 19:59:35 +00:00
|
|
|
.o_hs(VGA_HS),
|
|
|
|
.o_vs(VGA_VS),
|
2018-11-24 19:42:48 +00:00
|
|
|
.o_active(VGA_ACTIVE),
|
2018-11-11 11:10:40 +00:00
|
|
|
.o_x(x),
|
|
|
|
.o_y(y)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Draw one square
|
2018-11-25 19:47:30 +00:00
|
|
|
wire square = ((x >= box_x1) & (y >= box_y1) & (x <= box_x2) & (y <= box_y2)) ? 1 : 0; //Is box within range?
|
2018-11-21 11:21:28 +00:00
|
|
|
wire R = square ? box_color[0] : box_color[3];
|
|
|
|
wire G = square ? box_color[1] : box_color[4];
|
|
|
|
wire B = square ? box_color[2] : box_color[5];
|
|
|
|
assign VGA_R = VGA_ACTIVE ? R : 0; // Set R (Foreground and then background)
|
|
|
|
assign VGA_G = VGA_ACTIVE ? G : 0; // Set G
|
|
|
|
assign VGA_B = VGA_ACTIVE ? B : 0; // Set B
|
2018-11-11 11:10:40 +00:00
|
|
|
endmodule
|