diff --git a/fw/cpu/controller/process.c b/fw/cpu/controller/process.c index f9dc968..1958214 100644 --- a/fw/cpu/controller/process.c +++ b/fw/cpu/controller/process.c @@ -285,7 +285,7 @@ void cfg_update_config (uint32_t *args) { void cfg_set_save_type (uint8_t type) { CFG->SCR &= ~(CFG_SCR_FLASHRAM_EN | CFG_SCR_SRAM_BANKED | CFG_SCR_SRAM_EN); - uint32_t save_offset = 0; + uint32_t save_offset = DEFAULT_SAVE_OFFSET; switch (type) { case 0: { diff --git a/fw/rtl/cpu/cpu_flashram.sv b/fw/rtl/cpu/cpu_flashram.sv index f6eb4b5..dea857e 100644 --- a/fw/rtl/cpu/cpu_flashram.sv +++ b/fw/rtl/cpu/cpu_flashram.sv @@ -68,7 +68,7 @@ module cpu_flashram ( flashram.operation_done <= 1'b0; if (bus.request) begin - if (!bus.address[5] && bus.wmask[0]) begin + if (!bus.address[7] && bus.wmask[0]) begin flashram.operation_done <= bus.wdata[1]; end end diff --git a/fw/rtl/cpu/cpu_sdram.sv b/fw/rtl/cpu/cpu_sdram.sv index 438d691..4156e7c 100644 --- a/fw/rtl/cpu/cpu_sdram.sv +++ b/fw/rtl/cpu/cpu_sdram.sv @@ -44,7 +44,7 @@ module cpu_sdram ( bus.rdata = rdata; end - sdram.write = current_word ? &bus.wmask[3:2] : &bus.wmask[1:0]; + sdram.write = current_word ? &bus.wmask[1:0] : &bus.wmask[3:2]; sdram.address = {1'b0, bus.address[30:2], current_word, 1'b0}; sdram.wdata = current_word ? bus.wdata[15:0] : bus.wdata[31:16]; end diff --git a/fw/rtl/n64/n64_flashram.sv b/fw/rtl/n64/n64_flashram.sv index 92b0964..8f13e36 100644 --- a/fw/rtl/n64/n64_flashram.sv +++ b/fw/rtl/n64/n64_flashram.sv @@ -44,21 +44,25 @@ module n64_flashram ( logic [7:0] flashram_command; logic flashram_erase_enabled; - logic [1:0][15:0] write_buffer [0:31]; + logic [31:0] write_buffer [0:31]; logic [1:0] write_buffer_wmask; + logic [15:0] high_buffer; always_comb begin write_buffer_wmask = 2'b00; if (bus.request && bus.write && !bus.address[16] && flashram_state == FS_BUFFER) begin - write_buffer_wmask[0] = bus.address[1]; - write_buffer_wmask[1] = !bus.address[1]; + write_buffer_wmask[0] = !bus.address[1]; + write_buffer_wmask[1] = bus.address[1]; end end + always_ff @(posedge sys.clk) begin + if (write_buffer_wmask[0]) high_buffer <= bus.wdata; + end + always @(posedge sys.clk) begin - flashram.rdata <= {write_buffer[flashram.address][1], write_buffer[flashram.address][0]}; - if (write_buffer_wmask[0]) write_buffer[bus.address[6:2]][0] <= bus.wdata; - if (write_buffer_wmask[1]) write_buffer[bus.address[6:2]][1] <= bus.wdata; + flashram.rdata <= write_buffer[flashram.address]; + if (write_buffer_wmask[1]) write_buffer[bus.address[6:2]] <= {high_buffer, bus.wdata}; end always_comb begin