SummerCart64/fw/rtl/cpu/cpu_ram.sv

34 lines
864 B
Systemverilog
Raw Normal View History

module cpu_ram (
if_system.sys sys,
2022-02-02 19:07:43 +01:00
if_cpu_bus bus
);
2022-02-02 19:07:43 +01:00
logic [3:0][7:0] ram [0:8191];
logic [31:0] q;
always_ff @(posedge sys.clk) begin
bus.ack <= 1'b0;
if (bus.request) begin
bus.ack <= 1'b1;
end
end
always_comb begin
bus.rdata = 32'd0;
if (bus.ack) begin
2022-02-02 19:07:43 +01:00
bus.rdata = q;
end
end
2022-01-20 20:28:59 +01:00
always_ff @(posedge sys.clk) begin
2022-02-02 19:07:43 +01:00
q <= ram[bus.address[14:2]];
if (bus.request) begin
2022-02-02 19:07:43 +01:00
if (bus.wmask[0]) ram[bus.address[14:2]][0] <= bus.wdata[7:0];
if (bus.wmask[1]) ram[bus.address[14:2]][1] <= bus.wdata[15:8];
if (bus.wmask[2]) ram[bus.address[14:2]][2] <= bus.wdata[23:16];
if (bus.wmask[3]) ram[bus.address[14:2]][3] <= bus.wdata[31:24];
2022-01-20 20:28:59 +01:00
end
end
endmodule