SummerCart64/fw/rtl/cpu/cpu_ram.sv

45 lines
1.4 KiB
Systemverilog
Raw Normal View History

2021-08-15 21:49:02 +02:00
module cpu_ram(if_cpu_bus bus);
2021-08-12 21:07:47 +02:00
2021-08-18 13:54:07 +02:00
logic bank;
logic [3:0][7:0] ram_1 [0:4095];
// logic [3:0][7:0] ram_2 [0:2047];
logic [31:0] q_1;//, q_2;
// logic [31:0] q;
2021-08-05 19:50:29 +02:00
2021-08-15 21:49:02 +02:00
assign bank = bus.address[14];
always_comb begin
bus.rdata = 32'd0;
if (bus.ack) begin
bus.rdata = q_1;
2021-08-18 13:54:07 +02:00
// if (bank) bus.rdata = q_2;
2021-08-15 21:49:02 +02:00
end
end
always_ff @(posedge bus.clk) begin
bus.ack <= 1'b0;
if (bus.request) begin
bus.ack <= 1'b1;
end
end
2021-08-05 19:50:29 +02:00
2021-08-15 21:49:02 +02:00
always_ff @(posedge bus.clk) begin
q_1 <= ram_1[bus.address[13:2]];
if (bus.request & !bank) begin
if (bus.wmask[0]) ram_1[bus.address[13:2]][0] <= bus.wdata[7:0];
if (bus.wmask[1]) ram_1[bus.address[13:2]][1] <= bus.wdata[15:8];
if (bus.wmask[2]) ram_1[bus.address[13:2]][2] <= bus.wdata[23:16];
if (bus.wmask[3]) ram_1[bus.address[13:2]][3] <= bus.wdata[31:24];
2021-08-05 19:50:29 +02:00
end
2021-08-18 13:54:07 +02:00
// q_2 <= ram_2[bus.address[12:2]];
// if (bus.request & bank) begin
// if (bus.wmask[0]) ram_2[bus.address[12:2]][0] <= bus.wdata[7:0];
// if (bus.wmask[1]) ram_2[bus.address[12:2]][1] <= bus.wdata[15:8];
// if (bus.wmask[2]) ram_2[bus.address[12:2]][2] <= bus.wdata[23:16];
// if (bus.wmask[3]) ram_2[bus.address[12:2]][3] <= bus.wdata[31:24];
// end
2021-08-05 19:50:29 +02:00
end
endmodule