Add basic support for ED64 X series

Only loads ROM's
This commit is contained in:
Robin Jones 2024-06-08 13:45:59 +01:00
parent 83ed01a043
commit 1bb9746e1e
5 changed files with 203 additions and 2 deletions

View File

@ -30,6 +30,7 @@ SRCS = \
flashcart/64drive/64drive.c \ flashcart/64drive/64drive.c \
flashcart/flashcart_utils.c \ flashcart/flashcart_utils.c \
flashcart/flashcart.c \ flashcart/flashcart.c \
flashcart/ed64x/ed64x.c \
flashcart/sc64/sc64_ll.c \ flashcart/sc64/sc64_ll.c \
flashcart/sc64/sc64.c \ flashcart/sc64/sc64.c \
libs/libspng/spng/spng.c \ libs/libspng/spng/spng.c \

160
src/flashcart/ed64x/ed64x.c Normal file
View File

@ -0,0 +1,160 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <fatfs/ff.h>
#include <libdragon.h>
#include "utils/fs.h"
#include "utils/utils.h"
#include "../flashcart_utils.h"
#include "ed64x_ll.h"
#include "ed64x.h"
typedef enum {
ED64_X5 = 5,
ED64_X7 = 7,
ED64_UKNOWN = 0,
} ed64x_device_variant_t;
/* ED64 save location base address */
#define SRAM_ADDRESS (0xA8000000)
/* ED64 ROM location base address */
#define ROM_ADDRESS (0xB0000000)
static flashcart_err_t ed64x_init (void) {
return FLASHCART_OK;
}
static flashcart_err_t ed64x_deinit (void) {
return FLASHCART_OK;
}
static ed64x_device_variant_t get_cart_model() {
// Currently either X5 or X7
return true; // FIXME: check cart model.
}
static bool ed64x_has_feature (flashcart_features_t feature) {
bool is_model_x7 = get_cart_model();
switch (feature) {
case FLASHCART_FEATURE_RTC: return is_model_x7 ? true : false;
case FLASHCART_FEATURE_USB: return is_model_x7 ? true : false;
case FLASHCART_FEATURE_AUTO_CIC: return true;
case FLASHCART_FEATURE_64DD: return false;
default: return false;
}
}
static flashcart_err_t ed64x_load_rom (char *rom_path, flashcart_progress_callback_t *progress) {
FIL fil;
UINT br;
if (f_open(&fil, strip_fs_prefix(rom_path), FA_READ) != FR_OK) {
return FLASHCART_ERR_LOAD;
}
fatfs_fix_file_size(&fil);
size_t rom_size = f_size(&fil);
if (rom_size > MiB(64)) {
f_close(&fil);
return FLASHCART_ERR_LOAD;
}
size_t sdram_size = MiB(64);
size_t chunk_size = KiB(128);
for (int offset = 0; offset < sdram_size; offset += chunk_size) {
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_ERR_LOAD;
}
if (progress) {
progress(f_tell(&fil) / (float) (f_size(&fil)));
}
}
if (f_tell(&fil) != rom_size) {
f_close(&fil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&fil) != FR_OK) {
return FLASHCART_ERR_LOAD;
}
return FLASHCART_OK;
}
static flashcart_err_t ed64x_load_file (char *file_path, uint32_t rom_offset, uint32_t file_offset) {
FIL fil;
UINT br;
if (f_open(&fil, strip_fs_prefix(file_path), FA_READ) != FR_OK) {
return FLASHCART_ERR_LOAD;
}
fatfs_fix_file_size(&fil);
size_t file_size = f_size(&fil) - file_offset;
if (file_size > (MiB(64) - rom_offset)) {
f_close(&fil);
return FLASHCART_ERR_ARGS;
}
if (f_lseek(&fil, file_offset) != FR_OK) {
f_close(&fil);
return FLASHCART_ERR_LOAD;
}
if (f_read(&fil, (void *) (ROM_ADDRESS + rom_offset), file_size, &br) != FR_OK) {
f_close(&fil);
return FLASHCART_ERR_LOAD;
}
if (br != file_size) {
f_close(&fil);
return FLASHCART_ERR_LOAD;
}
if (f_close(&fil) != FR_OK) {
return FLASHCART_ERR_LOAD;
}
return FLASHCART_OK;
}
static flashcart_err_t ed64x_load_save (char *save_path) {
return FLASHCART_OK;
}
static flashcart_err_t ed64x_set_save_type (flashcart_save_type_t save_type) {
return FLASHCART_OK;
}
static flashcart_t flashcart_ed64x = {
.init = ed64x_init,
.deinit = ed64x_deinit,
.has_feature = ed64x_has_feature,
.load_rom = ed64x_load_rom,
.load_file = ed64x_load_file,
.load_save = ed64x_load_save,
.load_64dd_ipl = NULL,
.load_64dd_disk = NULL,
.set_save_type = ed64x_set_save_type,
.set_save_writeback = NULL,
};
flashcart_t *ed64x_get_flashcart (void) {
return &flashcart_ed64x;
}

View File

@ -0,0 +1,24 @@
/**
* @file ed64x.h
* @brief ED64 Xseries flashcart support
* @ingroup flashcart
*/
#ifndef FLASHCART_ED64X_H__
#define FLASHCART_ED64X_H__
#include "../flashcart.h"
/**
* @addtogroup ED64_Xseries
* @{
*/
flashcart_t *ed64x_get_flashcart (void);
/** @} */ /* ed64x */
#endif

View File

@ -0,0 +1,14 @@
/**
* @file ed64x_ll.h
* @brief ed64x flashcart low level access
* @ingroup flashcart
*/
#ifndef FLASHCART_ED64X_LL_H__
#define FLASHCART_ED64X_LL_H__
/** @} */ /* ed64x */
#endif

View File

@ -11,6 +11,7 @@
#include "flashcart_utils.h" #include "flashcart_utils.h"
#include "64drive/64drive.h" #include "64drive/64drive.h"
#include "ed64x/ed64x.h"
#include "sc64/sc64.h" #include "sc64/sc64.h"
@ -108,10 +109,11 @@ flashcart_err_t flashcart_init (const char **storage_prefix) {
flashcart = d64_get_flashcart(); flashcart = d64_get_flashcart();
break; break;
case CART_EDX: // Series X EverDrive-64 case CART_EDX: // Official EverDrive 64 Series X
flashcart = ed64x_get_flashcart();
break; break;
case CART_ED: // Original EverDrive-64 case CART_ED: // Series V EverDrive-64 or clone
break; break;
case CART_SC: // SummerCart64 case CART_SC: // SummerCart64