`timescale 1ns / 1ps `define MEMORY_IMAGE_FILE "empty.hex" // VERSION 1.2 /* 'a' ports are imem, 'b' are dmem, and 'c' ports are for the video * controller. */ module bram(addra, addrb, addrc, clka, clkc, dinb, douta, doutb, doutc, web, ena, enb); input [15:0] addra; input [15:0] addrb; input [15:0] addrc; input clka; input clkc; input [15:0] dinb; output [15:0] douta; output [15:0] doutb; output [15:0] doutc; input web; input ena; input enb; reg [15:0] RAM [65535:0]; reg [15:0] read_addra; reg [15:0] read_addrb; reg [15:0] read_addrc; integer f; initial begin f = 0; // check that memory image exists f = $fopen( `MEMORY_IMAGE_FILE, "r" ); if (f == 0) begin $display( "Memory image file: %s not found.", `MEMORY_IMAGE_FILE ); $stop; end $fclose( f ); // load memory image $readmemh(`MEMORY_IMAGE_FILE, RAM, 0, 65535); end always @(posedge clka) begin if (ena) begin read_addra <= addra; end if (enb) begin #1; if (web == 1'b1) RAM[addrb] <= dinb; read_addrb <= addrb; end end always @(posedge clkc) begin read_addrc <= addrc; end assign #(1) douta = RAM[read_addra]; assign #(1) doutb = RAM[read_addrb]; assign #(1) doutc = RAM[read_addrc]; endmodule // bram