// One line of delay: a single-port RAM in read-first mode. // On each enabled clock it returns the word stored at addr (written one // line earlier) and stores din in its place. This is the read-first RAM // template from lesson 14, so synthesis can map it to block RAM. `timescale 1ns / 1ps module line_buffer #( parameter int W = 640, // pixels per line parameter int DW = 8, localparam int AW = $clog2(W) ) ( input logic clk, input logic en, input logic [AW-1:0] addr, input logic [DW-1:0] din, output logic [DW-1:0] dout ); logic [DW-1:0] mem [W]; always_ff @(posedge clk) begin if (en) begin dout <= mem[addr]; // old contents: the pixel one line above mem[addr] <= din; end end endmodule