From 885015ba7551ab86710d47e72b1da929f0067299 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Sun, 25 Jun 2023 23:56:55 +0200 Subject: [PATCH] save bug fixes --- docs/03_n64_commands.md | 47 ++++++++++++++++++----------------- sw/controller/src/cfg.c | 6 ++++- sw/controller/src/sd.c | 4 +++ sw/controller/src/writeback.c | 4 +++ sw/controller/src/writeback.h | 1 + 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/docs/03_n64_commands.md b/docs/03_n64_commands.md index c12d6bc..7655977 100644 --- a/docs/03_n64_commands.md +++ b/docs/03_n64_commands.md @@ -4,26 +4,27 @@ ## N64 commands -| id | name | arg0 | arg1 | rsp0 | rsp1 | description | -| --- | --------------------- | ---------- | ------------ | ---------------- | -------------- | -------------------------------------------------- | -| `v` | **IDENTIFIER_GET** | --- | --- | identifier | --- | Get flashcart identifier `SCv2` | -| `V` | **VERSION_GET** | --- | --- | version | --- | Get flashcart firmware version | -| `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option | -| `C` | **CONFIG_SET** | config_id | new_value | --- | previous_value | Set config option and get previous value | -| `c` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option | -| `C` | **SETTING_SET** | setting_id | new_value | --- | --- | Set persistent setting option | -| `t` | **TIME_GET** | --- | --- | time_0 | time_1 | Get current RTC value | -| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set new RTC value | -| `m` | **USB_READ** | pi_address | length | --- | --- | Receive data from USB to flashcart | -| `M` | **USB_WRITE** | pi_address | length/type | --- | --- | Send data from from flashcart to USB | -| `u` | **USB_READ_STATUS** | --- | --- | read_status/type | length | Get USB read status and type/length | -| `U` | **USB_WRITE_STATUS** | --- | --- | write_status | --- | Get USB write status | -| `i` | **SD_CARD_OP** | pi_address | operation | --- | return_data | Perform special operation on SD card | -| `I` | **SD_SECTOR_SET** | sector | --- | --- | --- | Set starting sector for next SD card R/W operation | -| `s` | **SD_READ** | pi_address | sector_count | --- | --- | Read sectors from SD card to flashcart | -| `S` | **SD_WRITE** | pi_address | sector_count | --- | --- | Write sectors from flashcart to SD card | -| `D` | **DD_SD_INFO** | pi_address | table_size | --- | --- | Set 64DD disk SD sector info | -| `W` | **WRITEBACK_SD_INFO** | pi_address | --- | --- | --- | Load writeback SD sector table and enable it | -| `K` | **FLASH_PROGRAM** | pi_address | length | --- | --- | Program flash with bytes loaded into data buffer | -| `p` | **FLASH_WAIT_BUSY** | wait | --- | erase_block_size | --- | Wait until flash ready / get block erase size | -| `P` | **FLASH_ERASE_BLOCK** | pi_address | --- | --- | --- | Start flash block erase | +| id | name | arg0 | arg1 | rsp0 | rsp1 | description | +| --- | --------------------- | -------------- | ------------ | ---------------- | -------------- | ---------------------------------------------------------- | +| `v` | **IDENTIFIER_GET** | --- | --- | identifier | --- | Get flashcart identifier `SCv2` | +| `V` | **VERSION_GET** | --- | --- | version | --- | Get flashcart firmware version | +| `c` | **CONFIG_GET** | config_id | --- | --- | current_value | Get config option | +| `C` | **CONFIG_SET** | config_id | new_value | --- | previous_value | Set config option and get previous value | +| `c` | **SETTING_GET** | setting_id | --- | --- | current_value | Get persistent setting option | +| `C` | **SETTING_SET** | setting_id | new_value | --- | --- | Set persistent setting option | +| `t` | **TIME_GET** | --- | --- | time_0 | time_1 | Get current RTC value | +| `T` | **TIME_SET** | time_0 | time_1 | --- | --- | Set new RTC value | +| `m` | **USB_READ** | pi_address | length | --- | --- | Receive data from USB to flashcart | +| `M` | **USB_WRITE** | pi_address | length/type | --- | --- | Send data from from flashcart to USB | +| `u` | **USB_READ_STATUS** | --- | --- | read_status/type | length | Get USB read status and type/length | +| `U` | **USB_WRITE_STATUS** | --- | --- | write_status | --- | Get USB write status | +| `i` | **SD_CARD_OP** | pi_address | operation | --- | return_data | Perform special operation on SD card | +| `I` | **SD_SECTOR_SET** | sector | --- | --- | --- | Set starting sector for next SD card R/W operation | +| `s` | **SD_READ** | pi_address | sector_count | --- | --- | Read sectors from SD card to flashcart | +| `S` | **SD_WRITE** | pi_address | sector_count | --- | --- | Write sectors from flashcart to SD card | +| `D` | **DD_SD_INFO** | pi_address | table_size | --- | --- | Set 64DD disk SD sector info | +| `w` | **WRITEBACK_PENDING** | pending_status | --- | --- | --- | Get save writeback status (is write queued to the SD card) | +| `W` | **WRITEBACK_SD_INFO** | pi_address | --- | --- | --- | Load writeback SD sector table and enable it | +| `K` | **FLASH_PROGRAM** | pi_address | length | --- | --- | Program flash with bytes loaded into data buffer | +| `p` | **FLASH_WAIT_BUSY** | wait | --- | erase_block_size | --- | Wait until flash ready / get block erase size | +| `P` | **FLASH_ERASE_BLOCK** | pi_address | --- | --- | --- | Start flash block erase | diff --git a/sw/controller/src/cfg.c b/sw/controller/src/cfg.c index 7264817..2a0757c 100644 --- a/sw/controller/src/cfg.c +++ b/sw/controller/src/cfg.c @@ -178,7 +178,7 @@ static void cfg_change_scr_bits (uint32_t mask, bool value) { } static bool cfg_set_save_type (save_type_t save_type) { - if (save_type > SAVE_TYPE_SRAM_BANKED) { + if (save_type > SAVE_TYPE_SRAM_1M) { return true; } @@ -639,6 +639,10 @@ void cfg_process (void) { dd_set_sd_info(args[0], args[1]); break; + case 'w': + args[0] = writeback_pending(); + break; + case 'W': if (cfg_translate_address(&args[0], WRITEBACK_SECTOR_TABLE_SIZE, (SDRAM | BRAM))) { cfg_set_error(CFG_ERROR_BAD_ADDRESS); diff --git a/sw/controller/src/sd.c b/sw/controller/src/sd.c index 3a2f516..a07917c 100644 --- a/sw/controller/src/sd.c +++ b/sw/controller/src/sd.c @@ -424,6 +424,10 @@ bool sd_read_sectors (uint32_t address, uint32_t sector, uint32_t count) { return true; } + if (p.byte_swap && ((address % 2) != 0)) { + return true; + } + if (!p.card_type_block) { sector *= SD_SECTOR_SIZE; } diff --git a/sw/controller/src/writeback.c b/sw/controller/src/writeback.c index 39ded8e..8e65f05 100644 --- a/sw/controller/src/writeback.c +++ b/sw/controller/src/writeback.c @@ -124,6 +124,10 @@ void writeback_disable (void) { timer_set(TIMER_ID_WRITEBACK, 0); } +bool writeback_pending (void) { + return p.enabled && p.pending; +} + void writeback_init (void) { p.enabled = false; p.pending = false; diff --git a/sw/controller/src/writeback.h b/sw/controller/src/writeback.h index f1bff21..8e10b45 100644 --- a/sw/controller/src/writeback.h +++ b/sw/controller/src/writeback.h @@ -18,6 +18,7 @@ typedef enum { void writeback_load_sector_table (uint32_t address); void writeback_enable (writeback_mode_t mode); void writeback_disable (void); +bool writeback_pending (void); void writeback_init (void); void writeback_process (void);