[develop] Add basic support for ED64 X series ()

<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
Add basic support for ED64 X series
Only loads ROM's (no save support)

## Motivation and Context
<!--- What does this sample do? What problem does it solve? -->
<!--- If it fixes/closes/resolves an open issue, please link to the
issue here -->

## How Has This Been Tested?
<!-- (if applicable) -->
<!--- Please describe in detail how you tested your sample/changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots
<!-- (if appropriate): -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Improvement (non-breaking change that adds a new feature)
- [ ] Bug fix (fixes an issue)
- [ ] Breaking change (breaking change)
- [ ] Documentation Improvement
- [ ] Config and build (change in the configuration and build system,
has no impact on code or features)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [ ] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.

<!--- It would be nice if you could sign off your contribution by
replacing the name with your GitHub user name and GitHub email contact.
-->
Signed-off-by: GITHUB_USER <GITHUB_USER_EMAIL>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Added support for the ED64 Xseries flashcart, including initialization
and file management capabilities.

- **Bug Fixes**
- Improved clarity in flashcart initialization logic, ensuring accurate
handling of different flashcart types.

- **Documentation**
- Enhanced documentation comments across the codebase for better clarity
on functionalities and features.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Robin Jones 2025-01-12 12:41:47 +00:00 committed by GitHub
parent fe287b99d0
commit 8c89198466
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 212 additions and 6 deletions

@ -30,6 +30,7 @@ SRCS = \
flashcart/64drive/64drive.c \
flashcart/flashcart_utils.c \
flashcart/ed64/ed64_vseries.c \
flashcart/ed64/ed64_xseries.c \
flashcart/flashcart.c \
flashcart/sc64/sc64_ll.c \
flashcart/sc64/sc64.c \

@ -126,7 +126,8 @@ The aim is to reach feature parity with [ED64-UnofficialOS](https://github.com/n
Download the `OS64.v64` ROM from the latest [action run - assets] and place it in the `/ED64` folder.
#### ED64 (X series)
X Series support is currently awaiting fixes. Please use the official [OS](https://krikzz.com/pub/support/everdrive-64/x-series/OS/) for now.
The aim is to reach feature parity with [OS](https://krikzz.com/pub/support/everdrive-64/x-series/OS/) for now.
Download the `OS64.v64` ROM from the latest [action run - assets] and place it in the `/ED64` folder.
#### ED64 (P clone)
Download the `OS64P.v64` ROM from the latest [action run - assets] and place it in the `/ED64P` folder.

@ -9,6 +9,7 @@
#include "utils/utils.h"
#include "../flashcart_utils.h"
#include "ed64_vseries_ll.h"
#include "ed64_vseries.h"
typedef enum {

@ -0,0 +1,14 @@
/**
* @file ed64_vseries_ll.h
* @brief ed64v flashcart low level access
* @ingroup flashcart
*/
#ifndef FLASHCART_ED64_VSERIES_LL_H__
#define FLASHCART_ED64_VSERIES_LL_H__
/** @} */ /* ed64_vseries_ll */
#endif

@ -0,0 +1,175 @@
#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 "ed64_xseries_ll.h"
#include "ed64_xseries.h"
typedef enum {
// potentially handle if the firmware supports it...
ED64_X5_0 = 550,
ED64_X7_0 = 570,
ED64_UKNOWN = 0,
} ed64_xseries_device_variant_t;
/* ED64 save location base address */
#define SRAM_ADDRESS (0xA8000000)
/* ED64 ROM location base address */
#define ROM_ADDRESS (0xB0000000)
static flashcart_firmware_version_t ed64_xseries_get_firmware_version (void) {
flashcart_firmware_version_t version_info;
// FIXME: get version from ll
version_info.major = 1;
version_info.minor = 1;
version_info.revision = 0;
//ed64_ll_get_version(&version_info.major, &version_info.minor, &version_info.revision);
return version_info;
}
static flashcart_err_t ed64_xseries_init (void) {
return FLASHCART_OK;
}
static flashcart_err_t ed64_xseries_deinit (void) {
return FLASHCART_OK;
}
static ed64_xseries_device_variant_t get_cart_model() {
ed64_xseries_device_variant_t variant = ED64_X7_0; // FIXME: check cart model from ll for better feature handling.
return variant;
}
static bool ed64_xseries_has_feature (flashcart_features_t feature) {
bool is_model_x7 = (get_cart_model() == ED64_X7_0);
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_64DD: return false;
case FLASHCART_FEATURE_AUTO_CIC: return true;
case FLASHCART_FEATURE_AUTO_REGION: return true;
default: return false;
}
}
static flashcart_err_t ed64_xseries_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 ed64_xseries_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 ed64_xseries_load_save (char *save_path) {
return FLASHCART_OK;
}
static flashcart_err_t ed64_xseries_set_save_type (flashcart_save_type_t save_type) {
return FLASHCART_OK;
}
static flashcart_t flashcart_ed64_xseries = {
.init = ed64_xseries_init,
.deinit = ed64_xseries_deinit,
.has_feature = ed64_xseries_has_feature,
.get_firmware_version = ed64_xseries_get_firmware_version,
.load_rom = ed64_xseries_load_rom,
.load_file = ed64_xseries_load_file,
.load_save = ed64_xseries_load_save,
.load_64dd_ipl = NULL,
.load_64dd_disk = NULL,
.set_save_type = ed64_xseries_set_save_type,
.set_save_writeback = NULL,
};
flashcart_t *ed64_xseries_get_flashcart (void) {
return &flashcart_ed64_xseries;
}

@ -16,7 +16,7 @@
* @{
*/
flashcart_t *ed64xseries_get_flashcart (void);
flashcart_t *ed64_xseries_get_flashcart (void);
/** @} */ /* ED64_Xseries */

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

@ -11,6 +11,7 @@
#include "flashcart_utils.h"
#include "ed64/ed64_vseries.h"
#include "ed64/ed64_xseries.h"
#include "64drive/64drive.h"
#include "sc64/sc64.h"
@ -109,10 +110,9 @@ flashcart_err_t flashcart_init (const char **storage_prefix) {
flashcart = d64_get_flashcart();
break;
// FIXME: this is commented out awaiting a fix from libcart.
// case CART_EDX: // Series X EverDrive-64
// flashcart = ed64_xseries_get_flashcart();
// break;
case CART_EDX: // Official EverDrive 64 Series X
flashcart = ed64_xseries_get_flashcart();
break;
case CART_ED: // Series V EverDrive-64 or clone
flashcart = ed64_vseries_get_flashcart();