mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-22 02:29:19 +01:00
Added SC64 API version check
This commit is contained in:
parent
992fcf4923
commit
22656b150c
@ -25,21 +25,21 @@ static const size_t SAVE_SIZE[__FLASHCART_SAVE_TYPE_END] = {
|
||||
static flashcart_t *flashcart;
|
||||
|
||||
|
||||
bool flashcart_init (void) {
|
||||
flashcart_error_t flashcart_init (void) {
|
||||
switch (usb_getcart()) {
|
||||
case CART_SC64:
|
||||
flashcart = sc64_get_flashcart();
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
return FLASHCART_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return flashcart->init();
|
||||
}
|
||||
|
||||
void flashcart_deinit (void) {
|
||||
flashcart->deinit();
|
||||
flashcart_error_t flashcart_deinit (void) {
|
||||
return flashcart->deinit();
|
||||
}
|
||||
|
||||
flashcart_error_t flashcart_load_rom (char *rom_path) {
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
typedef enum {
|
||||
FLASHCART_OK,
|
||||
FLASHCART_ERROR_UNSUPPORTED,
|
||||
FLASHCART_ERROR_OUTDATED,
|
||||
FLASHCART_ERROR_ARGS,
|
||||
FLASHCART_ERROR_LOAD,
|
||||
FLASHCART_ERROR_INT,
|
||||
@ -25,8 +27,8 @@ typedef enum {
|
||||
} flashcart_save_type_t;
|
||||
|
||||
typedef struct {
|
||||
bool (*init) (void);
|
||||
void (*deinit) (void);
|
||||
flashcart_error_t (*init) (void);
|
||||
flashcart_error_t (*deinit) (void);
|
||||
flashcart_error_t (*load_rom) (char *rom_path);
|
||||
flashcart_error_t (*load_save) (char *save_path);
|
||||
flashcart_error_t (*set_save_type) (flashcart_save_type_t save_type);
|
||||
@ -34,8 +36,8 @@ typedef struct {
|
||||
} flashcart_t;
|
||||
|
||||
|
||||
bool flashcart_init (void);
|
||||
void flashcart_deinit (void);
|
||||
flashcart_error_t flashcart_init (void);
|
||||
flashcart_error_t flashcart_deinit (void);
|
||||
flashcart_error_t flashcart_load_rom (char *rom_path);
|
||||
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type, bool save_writeback);
|
||||
|
||||
|
@ -12,11 +12,13 @@
|
||||
#include "sc64.h"
|
||||
|
||||
|
||||
#define SRAM_FLASHRAM_ADDRESS (0x08000000)
|
||||
#define ROM_ADDRESS (0x10000000)
|
||||
#define EXTENDED_ADDRESS (0x14000000)
|
||||
#define SHADOW_ADDRESS (0x1FFC0000)
|
||||
#define EEPROM_ADDRESS (0x1FFE2000)
|
||||
#define SRAM_FLASHRAM_ADDRESS (0x08000000)
|
||||
#define ROM_ADDRESS (0x10000000)
|
||||
#define EXTENDED_ADDRESS (0x14000000)
|
||||
#define SHADOW_ADDRESS (0x1FFC0000)
|
||||
#define EEPROM_ADDRESS (0x1FFE2000)
|
||||
|
||||
#define MIN_SUPPORTED_API_VERSION (1)
|
||||
|
||||
|
||||
static flashcart_error_t load_to_flash (FIL *fil, void *address, size_t size, UINT *br) {
|
||||
@ -49,13 +51,29 @@ static flashcart_error_t load_to_flash (FIL *fil, void *address, size_t size, UI
|
||||
}
|
||||
|
||||
|
||||
static bool sc64_init (void) {
|
||||
static flashcart_error_t sc64_init (void) {
|
||||
uint32_t api_version;
|
||||
|
||||
sc64_unlock();
|
||||
return sc64_check_presence();
|
||||
|
||||
if (!sc64_check_presence()) {
|
||||
return FLASHCART_ERROR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (sc64_get_api_version(&api_version) != SC64_OK) {
|
||||
return FLASHCART_ERROR_OUTDATED;
|
||||
}
|
||||
|
||||
if (api_version < MIN_SUPPORTED_API_VERSION) {
|
||||
return FLASHCART_ERROR_OUTDATED;
|
||||
}
|
||||
|
||||
return FLASHCART_OK;
|
||||
}
|
||||
|
||||
static void sc64_deinit (void) {
|
||||
static flashcart_error_t sc64_deinit (void) {
|
||||
sc64_lock();
|
||||
return FLASHCART_OK;
|
||||
}
|
||||
|
||||
static flashcart_error_t sc64_load_rom (char *rom_path) {
|
||||
|
@ -26,6 +26,7 @@ typedef struct {
|
||||
|
||||
|
||||
typedef enum {
|
||||
CMD_ID_API_VERSION_GET = 'V',
|
||||
CMD_ID_CONFIG_GET = 'c',
|
||||
CMD_ID_CONFIG_SET = 'C',
|
||||
CMD_ID_WRITEBACK_SD_INFO = 'W',
|
||||
@ -89,6 +90,13 @@ void sc64_write_data (void *src, void *dst, size_t length) {
|
||||
dma_wait();
|
||||
}
|
||||
|
||||
sc64_error_t sc64_get_api_version (uint32_t *api_version) {
|
||||
sc64_cmd_t cmd = { .id = CMD_ID_API_VERSION_GET };
|
||||
sc64_error_t error = sc64_execute_cmd(&cmd);
|
||||
*api_version = cmd.rsp[0];
|
||||
return error;
|
||||
}
|
||||
|
||||
sc64_error_t sc64_get_config (sc64_cfg_t id, void *value) {
|
||||
sc64_cmd_t cmd = { .id = CMD_ID_CONFIG_GET, .arg = { id } };
|
||||
sc64_error_t error = sc64_execute_cmd(&cmd);
|
||||
|
@ -60,6 +60,7 @@ void sc64_lock (void);
|
||||
bool sc64_check_presence (void);
|
||||
void sc64_read_data (void *src, void *dst, size_t length);
|
||||
void sc64_write_data (void *src, void *dst, size_t length);
|
||||
sc64_error_t sc64_get_api_version (uint32_t *api_version);
|
||||
sc64_error_t sc64_get_config (sc64_cfg_t cfg, void *value);
|
||||
sc64_error_t sc64_set_config (sc64_cfg_t cfg, uint32_t value);
|
||||
sc64_error_t sc64_writeback_enable (void *address);
|
||||
|
14
src/main.c
14
src/main.c
@ -10,8 +10,20 @@
|
||||
|
||||
static void init (void) {
|
||||
assertf(usb_initialize() != CART_NONE, "No flashcart was detected");
|
||||
switch (flashcart_init()) {
|
||||
case FLASHCART_OK:
|
||||
break;
|
||||
case FLASHCART_ERROR_OUTDATED:
|
||||
assertf(false, "Outdated flashcart firmware");
|
||||
break;
|
||||
case FLASHCART_ERROR_UNSUPPORTED:
|
||||
assertf(false, "Unsupported flashcart");
|
||||
break;
|
||||
default:
|
||||
assertf(false, "Unknown error while initializing flashcart");
|
||||
break;
|
||||
}
|
||||
assertf(debug_init_sdfs("sd:/", -1), "Couldn't initialize SD card");
|
||||
assertf(flashcart_init(), "Couldn't initialize flashcart");
|
||||
}
|
||||
|
||||
static void deinit (void) {
|
||||
|
Loading…
Reference in New Issue
Block a user