module memspram #(
    parameter ADDR_WIDTH = 14
) (
    input clk,
    input reset_n,
    output[7:0] data_out,
    input[7:0] data_in,
    input cs_n,
    input rd_n,
    input wr_n,
    input[ADDR_WIDTH-1:0] addr
);

    wire read_sel = !cs_n & !rd_n & wr_n;
    wire write_sel = !cs_n & rd_n & !wr_n;

	wire [15:0] spram_q;
	assign data_out = (read_sel) ? spram_q[7:0] : 8'b0;

	//SB_SPRAM256KA.ADDRESS is 14bit:
	wire [13:0] addr_sp;
	assign addr_sp = addr;

	SB_SPRAM256KA ram0
	(
		.ADDRESS(addr_sp),
		.DATAIN({8'b0, data_in}),
		.MASKWREN(4'b0011),
		.WREN(write_sel),
		.CHIPSELECT(1'b1),
		.CLOCK(clk),
		.STANDBY(1'b0),
		.SLEEP(1'b0),
		.POWEROFF(1'b1),
		.DATAOUT(spram_q)
	);

endmodule