SC64 libcart PI setting fix

This commit is contained in:
Mateusz Faderewski 2023-07-11 10:58:49 +02:00
parent da49393d6f
commit 02010f1cbb
9 changed files with 34 additions and 24 deletions

View File

@ -38,18 +38,12 @@ static flashcart_t *flashcart = &((flashcart_t) {
flashcart_error_t flashcart_init (void) {
flashcart_error_t error;
if (usb_initialize() == CART_NONE) {
return FLASHCART_ERROR_NOT_DETECTED;
}
#ifndef NDEBUG
assertf(debug_init_usblog(), "Couldn't initialize USB debugging");
#endif
if (!debug_init_sdfs("sd:/", -1)) {
return FLASHCART_ERROR_SD_CARD_ERROR;
}
switch (usb_getcart()) {
case CART_64DRIVE:
case CART_EVERDRIVE:
@ -63,7 +57,19 @@ flashcart_error_t flashcart_init (void) {
return FLASHCART_ERROR_UNSUPPORTED;
}
return flashcart->init();
if ((error = flashcart->init()) != FLASHCART_OK) {
return error;
}
if (!debug_init_sdfs("sd:/", -1)) {
return FLASHCART_ERROR_SD_CARD_ERROR;
}
#ifndef NDEBUG
assertf(debug_init_usblog(), "Couldn't initialize USB debugging");
#endif
return FLASHCART_OK;
}
flashcart_error_t flashcart_deinit (void) {
@ -80,7 +86,7 @@ flashcart_error_t flashcart_load_rom (char *rom_path, bool byte_swap) {
return flashcart->load_rom(rom_path, byte_swap);
}
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type, bool save_writeback) {
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type) {
flashcart_error_t error;
uint32_t sectors[WRITEBACK_MAX_SECTORS] __attribute__((aligned(8)));
@ -110,7 +116,7 @@ flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t sa
return error;
}
if (save_writeback) {
if (flashcart->set_save_writeback) {
if (file_get_sectors(save_path, sectors, WRITEBACK_MAX_SECTORS)) {
return FLASHCART_ERROR_LOAD;
}

View File

@ -41,7 +41,7 @@ typedef struct {
flashcart_error_t flashcart_init (void);
flashcart_error_t flashcart_deinit (void);
flashcart_error_t flashcart_load_rom (char *rom_path, bool byte_swap);
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type, bool save_writeback);
flashcart_error_t flashcart_load_save (char *save_path, flashcart_save_type_t save_type);
#endif

View File

@ -61,6 +61,12 @@ static flashcart_error_t sc64_init (void) {
uint16_t major;
uint16_t minor;
// HACK: Because libcart reads PI config from address 0x10000000 when initializing
// we need to write safe value before running any libcart function.
// Data in SDRAM can be undefined at this point and result in setting incorrect PI config.
extern uint32_t cart_dom1;
cart_dom1 = 0x80371240;
sc64_unlock();
if (!sc64_check_presence()) {
@ -87,6 +93,7 @@ static flashcart_error_t sc64_init (void) {
}
static flashcart_error_t sc64_deinit (void) {
sc64_set_config(CFG_ROM_WRITE_ENABLE, false);
sc64_lock();
return FLASHCART_OK;
}

View File

@ -1,8 +1,8 @@
#include <libdragon.h>
#include "../menu_res_setup.h"
#include "views.h"
#include "../menu_res_setup.h"
#ifndef MENU_VERSION
#define MENU_VERSION "0.0.0.4"

View File

@ -1,7 +1,7 @@
#include <libdragon.h>
#include "views.h"
#include "../menu_res_setup.h"
#include "views.h"
static void process (menu_t *menu) {

View File

@ -1,13 +1,11 @@
#include <fatfs/ff.h>
#include <libdragon.h>
#include "views.h"
#include "../menu_res_setup.h"
#include "../../utils/str_utils.h"
#include "../rom_database.h"
#include "fragments/fragments.h"
#include "utils/str_utils.h"
#include "views.h"
static FILINFO info;

View File

@ -1,10 +1,9 @@
#include <libdragon.h>
#include "../rom_database.h"
#include "flashcart/flashcart.h"
#include "fragments/fragments.h"
#include "views.h"
#include "../rom_database.h"
static bool load_pending;
@ -101,7 +100,7 @@ static void load (menu_t *menu) {
uint8_t save_type = rom_db_match_save_type(rom_header);
path_ext_replace(path, "sav");
menu->flashcart_error = flashcart_load_save(path_get(path), convert_save_type(save_type), true);
menu->flashcart_error = flashcart_load_save(path_get(path), convert_save_type(save_type));
if (menu->flashcart_error != FLASHCART_OK) {
menu->next_mode = MENU_MODE_FAULT;
path_free(path);

View File

@ -1,10 +1,9 @@
#include <libdragon.h>
#include "../mp3player.h"
#include "fragments/fragments.h"
#include "views.h"
#include "../mp3player.h"
#define SEEK_SECONDS 10
#define SEEK_UNMUTE_TIMEOUT 17

View File

@ -1,8 +1,9 @@
#include <time.h>
#include <libdragon.h>
#include "views.h"
#include "../menu_res_setup.h"
#include "views.h"
char *accessory_type_s( int accessory )