Skip to content

Commit

Permalink
Fix merge
Browse files Browse the repository at this point in the history
Add fixes for latest main branch
  • Loading branch information
networkfusion committed Dec 28, 2023
1 parent a117a3e commit 68293be
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ SRCS = \
flashcart/sc64/sc64.c \
flashcart/ed64/ed64_ll.c \
flashcart/ed64/ed64.c \
hdmi/hdmi.c \
libs/libspng/spng/spng.c \
libs/mini.c/src/mini.c \
libs/miniz/miniz_tdef.c \
Expand Down
56 changes: 33 additions & 23 deletions src/flashcart/ed64/ed64.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

extern int ed_exit(void);

static flashcart_error_t ed64_init (void) {
static flashcart_err_t ed64_init (void) {

// TODO: partly already done, see https://github.com/DragonMinded/libdragon/blob/4ec469d26b6dc4e308caf3d5b86c2b340b708bbd/src/libcart/cart.c#L1064

Expand All @@ -36,7 +36,7 @@ static flashcart_error_t ed64_init (void) {
return FLASHCART_OK;
}

static flashcart_error_t ed64_deinit (void) {
static flashcart_err_t ed64_deinit (void) {

// ed64_ll_gpio_mode_off(); // On V3 or X7, this should be ed64_bios_gpio_mode_rtc() if it is required.

Expand All @@ -46,12 +46,19 @@ static flashcart_error_t ed64_deinit (void) {
return FLASHCART_OK;
}

static flashcart_error_t ed64_load_rom (char *rom_path, flashcart_progress_callback_t *progress) {
static bool ed64_has_feature (flashcart_features_t feature) {
switch (feature) {
case FLASHCART_FEATURE_64DD: return false;
default: return false;
}
}

static flashcart_err_t ed64_load_rom (char *rom_path, flashcart_progress_callback_t *progress) {
FIL fil;
UINT br;

if (f_open(&fil, strip_sd_prefix(rom_path), FA_READ) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

fix_file_size(&fil);
Expand All @@ -61,7 +68,7 @@ static flashcart_error_t ed64_load_rom (char *rom_path, flashcart_progress_callb
// FIXME: if the cart is not V3 or X5 or X7, we need to - 128KiB
if (rom_size > MiB(64) - KiB(128)) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}


Expand All @@ -72,31 +79,31 @@ static flashcart_error_t ed64_load_rom (char *rom_path, flashcart_progress_callb
size_t block_size = MIN(sdram_size - offset, chunk_size);
if (f_read(&fil, (void *) (ROM_ADDRESS + offset), block_size, &br) != FR_OK) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}
if (progress) {
progress(f_tell(&fil) / (float) (f_size(&fil)));
}
}
if (f_tell(&fil) != sdram_size) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}


if (f_close(&fil) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

return FLASHCART_OK;
}

static flashcart_error_t ed64_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) {
static flashcart_err_t ed64_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) {
FIL fil;
UINT br;

if (f_open(&fil, strip_sd_prefix(file_path), FA_READ) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

fix_file_size(&fil);
Expand All @@ -106,31 +113,31 @@ static flashcart_error_t ed64_load_file (char *file_path, uint32_t rom_offset, u
// FIXME: if the cart is not V3 or X5 or X7, we need to - 128KiB
if (file_size > (MiB(64) - KiB(128) - rom_offset)) {
f_close(&fil);
return FLASHCART_ERROR_ARGS;
return FLASHCART_ERR_ARGS;
}

if (f_lseek(&fil, file_offset) != FR_OK) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

if (f_read(&fil, (void *) (ROM_ADDRESS + rom_offset), file_size, &br) != FR_OK) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}
if (br != file_size) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

if (f_close(&fil) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

return FLASHCART_OK;
}

static flashcart_error_t ed64_load_save (char *save_path) {
static flashcart_err_t ed64_load_save (char *save_path) {
void *address = NULL;
ed64_save_type_t type = ed64_ll_get_save_type();

Expand All @@ -146,35 +153,35 @@ static flashcart_error_t ed64_load_save (char *save_path) {
break;
case SAVE_TYPE_NONE:
default:
return FLASHCART_ERROR_ARGS;
return FLASHCART_ERR_ARGS;
}

FIL fil;
UINT br;

if (f_open(&fil, strip_sd_prefix(save_path), FA_READ) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

size_t save_size = f_size(&fil);

if (f_read(&fil, address, save_size, &br) != FR_OK) {
f_close(&fil);
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

if (f_close(&fil) != FR_OK) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

if (br != save_size) {
return FLASHCART_ERROR_LOAD;
return FLASHCART_ERR_LOAD;
}

return FLASHCART_OK;
}

static flashcart_error_t ed64_set_save_type (flashcart_save_type_t save_type) {
static flashcart_err_t ed64_set_save_type (flashcart_save_type_t save_type) {
ed64_save_type_t type;

switch (save_type) {
Expand All @@ -198,7 +205,7 @@ static flashcart_error_t ed64_set_save_type (flashcart_save_type_t save_type) {
type = SAVE_TYPE_FLASHRAM;
break;
default:
return FLASHCART_ERROR_ARGS;
return FLASHCART_ERR_ARGS;
}

ed64_ll_set_save_type(type);
Expand All @@ -210,9 +217,12 @@ static flashcart_error_t ed64_set_save_type (flashcart_save_type_t save_type) {
static flashcart_t flashcart_ed64 = {
.init = ed64_init,
.deinit = ed64_deinit,
.has_feature = ed64_has_feature,
.load_rom = ed64_load_rom,
.load_file = ed64_load_file,
.load_save = ed64_load_save,
.load_64dd_ipl = NULL,
.load_64dd_disk = NULL,
.set_save_type = ed64_set_save_type,
.set_save_writeback = NULL,
};
Expand Down

0 comments on commit 68293be

Please sign in to comment.