mirror of
https://github.com/Polprzewodnikowy/N64FlashcartMenu.git
synced 2024-11-25 03:56:54 +01:00
Improve code style
Function names. file names. things included in header.
This commit is contained in:
parent
9ef2f2d8a4
commit
11d90fdc1a
@ -17,13 +17,13 @@
|
|||||||
|
|
||||||
// This is a trial hack before using the settings API.
|
// This is a trial hack before using the settings API.
|
||||||
#ifndef LAST_SAVE_FILE_PATH
|
#ifndef LAST_SAVE_FILE_PATH
|
||||||
#define LAST_SAVE_FILE_PATH "/menu/last_rom.txt"
|
#define LAST_SAVE_FILE_PATH "/menu/last_rom.tmp"
|
||||||
#endif
|
#endif
|
||||||
#ifndef RESET_CHECK_FILE_PATH
|
#ifndef RESET_CHECK_FILE_PATH
|
||||||
#define RESET_CHECK_FILE_PATH "/menu/RESET"
|
#define RESET_CHECK_FILE_PATH "/menu/reset.tmp"
|
||||||
#endif
|
#endif
|
||||||
#ifndef FLASHRAM_CHECK_FILE_PATH
|
#ifndef FLASHRAM_CHECK_FILE_PATH
|
||||||
#define FLASHRAM_CHECK_FILE_PATH "/menu/FLASHRAM"
|
#define FLASHRAM_CHECK_FILE_PATH "/menu/flashram.tmp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int ed_exit(void);
|
extern int ed_exit(void);
|
||||||
@ -35,7 +35,7 @@ static flashcart_err_t ed64_init(void)
|
|||||||
// FIXME: Update firmware if needed.
|
// FIXME: Update firmware if needed.
|
||||||
// FIXME: Enable RTC if available.
|
// FIXME: Enable RTC if available.
|
||||||
|
|
||||||
// older everdrives cant save during gameplay so we need to the reset method.
|
// older everdrives cannot save during gameplay so we need to the reset method.
|
||||||
// works by checking if a file exists.
|
// works by checking if a file exists.
|
||||||
|
|
||||||
if (file_exists(strip_sd_prefix(RESET_CHECK_FILE_PATH)))
|
if (file_exists(strip_sd_prefix(RESET_CHECK_FILE_PATH)))
|
||||||
@ -68,7 +68,7 @@ static flashcart_err_t ed64_init(void)
|
|||||||
return FLASHCART_ERR_LOAD;
|
return FLASHCART_ERR_LOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now save the content back to the SD!
|
// Now save the content back to the SD card!
|
||||||
FIL fil;
|
FIL fil;
|
||||||
UINT br;
|
UINT br;
|
||||||
uint8_t cartsave_data[KiB(128)];
|
uint8_t cartsave_data[KiB(128)];
|
||||||
@ -88,17 +88,17 @@ static flashcart_err_t ed64_init(void)
|
|||||||
// so minus flashram we can just check the size
|
// so minus flashram we can just check the size
|
||||||
if (file_exists(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH)))
|
if (file_exists(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH)))
|
||||||
{ // flashram is bugged atm
|
{ // flashram is bugged atm
|
||||||
getFlashRAM(cartsave_data, save_size);
|
ed64_ll_get_fram(cartsave_data, save_size);
|
||||||
// deletes flag
|
// deletes flag
|
||||||
f_unlink(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH));
|
f_unlink(strip_sd_prefix(FLASHRAM_CHECK_FILE_PATH));
|
||||||
}
|
}
|
||||||
else if (save_size > KiB(2))
|
else if (save_size > KiB(2))
|
||||||
{ // sram
|
{ // sram
|
||||||
getSRAM(cartsave_data, save_size);
|
ed64_ll_get_sram(cartsave_data, save_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // eeprom
|
{ // eeprom
|
||||||
getEeprom(cartsave_data, save_size);
|
ed64_ll_get_eeprom(cartsave_data, save_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f_write(&fil, cartsave_data, save_size, &br) != FR_OK)
|
if (f_write(&fil, cartsave_data, save_size, &br) != FR_OK)
|
||||||
@ -272,14 +272,14 @@ static flashcart_err_t ed64_load_save(char *save_path)
|
|||||||
{
|
{
|
||||||
case SAVE_TYPE_EEPROM_4K:
|
case SAVE_TYPE_EEPROM_4K:
|
||||||
case SAVE_TYPE_EEPROM_16K:
|
case SAVE_TYPE_EEPROM_16K:
|
||||||
setEeprom(cartsave_data, save_size);
|
ed64_ll_set_eeprom(cartsave_data, save_size);
|
||||||
break;
|
break;
|
||||||
case SAVE_TYPE_SRAM:
|
case SAVE_TYPE_SRAM:
|
||||||
case SAVE_TYPE_SRAM_128K:
|
case SAVE_TYPE_SRAM_128K:
|
||||||
setSRAM(cartsave_data, save_size);
|
ed64_ll_set_sram(cartsave_data, save_size);
|
||||||
break;
|
break;
|
||||||
case SAVE_TYPE_FLASHRAM:
|
case SAVE_TYPE_FLASHRAM:
|
||||||
setFlashRAM(cartsave_data, save_size);
|
ed64_ll_set_fram(cartsave_data, save_size);
|
||||||
// a cold and warm boot has no way of seeing save types and most types can be determined by size
|
// a cold and warm boot has no way of seeing save types and most types can be determined by size
|
||||||
// this tells the cart to use flash instead of sram 128 since they are the same size
|
// this tells the cart to use flash instead of sram 128 since they are the same size
|
||||||
FIL flashfil;
|
FIL flashfil;
|
||||||
|
@ -24,6 +24,14 @@ typedef enum {
|
|||||||
|
|
||||||
} ed64_registers_t;
|
} ed64_registers_t;
|
||||||
|
|
||||||
|
void pi_initialize(void);
|
||||||
|
void pi_initialize_sram(void);
|
||||||
|
void pi_dma_from_cart(void* dest, void* src, unsigned long size);
|
||||||
|
void pi_dma_to_cart(void* dest, void* src, unsigned long size);
|
||||||
|
void pi_dma_from_sram(void *dest, unsigned long offset, unsigned long size);
|
||||||
|
void pi_dma_to_sram(void* src, unsigned long offset, unsigned long size);
|
||||||
|
void pi_dma_from_cart_safe(void *dest, void *src, unsigned long size);
|
||||||
|
|
||||||
|
|
||||||
#define SAV_EEP_ON 1
|
#define SAV_EEP_ON 1
|
||||||
#define SAV_SRM_ON 2
|
#define SAV_SRM_ON 2
|
||||||
@ -116,13 +124,13 @@ void ed64_ll_set_sram_bank(uint8_t bank) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PI_Init(void) {
|
void pi_initialize(void) {
|
||||||
dma_wait();
|
dma_wait();
|
||||||
io_write(PI_STATUS_REG, 0x03);
|
io_write(PI_STATUS_REG, 0x03);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inits PI for sram transfer
|
// Inits PI for sram transfer
|
||||||
void PI_Init_SRAM(void) {
|
void pi_initialize_sram(void) {
|
||||||
|
|
||||||
io_write(PI_BSD_DOM2_LAT_REG, 0x05);
|
io_write(PI_BSD_DOM2_LAT_REG, 0x05);
|
||||||
io_write(PI_BSD_DOM2_PWD_REG, 0x0C);
|
io_write(PI_BSD_DOM2_PWD_REG, 0x0C);
|
||||||
@ -131,7 +139,7 @@ void PI_Init_SRAM(void) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PI_DMAFromSRAM(void *dest, unsigned long offset, unsigned long size) {
|
void pi_dma_from_sram(void *dest, unsigned long offset, unsigned long size) {
|
||||||
|
|
||||||
|
|
||||||
io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest));
|
io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest));
|
||||||
@ -143,7 +151,7 @@ void PI_DMAFromSRAM(void *dest, unsigned long offset, unsigned long size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PI_DMAToSRAM(void *src, unsigned long offset, unsigned long size) { //void*
|
void pi_dma_to_sram(void *src, unsigned long offset, unsigned long size) { //void*
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
io_write(PI_STATUS_REG, 2);
|
io_write(PI_STATUS_REG, 2);
|
||||||
@ -152,7 +160,7 @@ void PI_DMAToSRAM(void *src, unsigned long offset, unsigned long size) { //void*
|
|||||||
io_write(PI_RD_LEN_REG, (size - 1));
|
io_write(PI_RD_LEN_REG, (size - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PI_DMAFromCart(void* dest, void* src, unsigned long size) {
|
void pi_dma_from_cart(void* dest, void* src, unsigned long size) {
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
io_write(PI_STATUS_REG, 0x03);
|
io_write(PI_STATUS_REG, 0x03);
|
||||||
@ -162,7 +170,7 @@ void PI_DMAFromCart(void* dest, void* src, unsigned long size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void PI_DMAToCart(void* dest, void* src, unsigned long size) {
|
void pi_dma_to_cart(void* dest, void* src, unsigned long size) {
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
io_write(PI_STATUS_REG, 0x02);
|
io_write(PI_STATUS_REG, 0x02);
|
||||||
@ -173,7 +181,7 @@ void PI_DMAToCart(void* dest, void* src, unsigned long size) {
|
|||||||
|
|
||||||
|
|
||||||
// Wrapper to support unaligned access to memory
|
// Wrapper to support unaligned access to memory
|
||||||
void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size) {
|
void pi_dma_from_cart_safe(void *dest, void *src, unsigned long size) {
|
||||||
if (!dest || !src || !size) return;
|
if (!dest || !src || !size) return;
|
||||||
|
|
||||||
unsigned long unalignedSrc = ((unsigned long)src) % 2;
|
unsigned long unalignedSrc = ((unsigned long)src) % 2;
|
||||||
@ -181,7 +189,7 @@ void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size) {
|
|||||||
|
|
||||||
//FIXME: Do i really need to check if size is 16bit aligned?
|
//FIXME: Do i really need to check if size is 16bit aligned?
|
||||||
if (!unalignedDest && !unalignedSrc && !(size % 2)) {
|
if (!unalignedDest && !unalignedSrc && !(size % 2)) {
|
||||||
PI_DMAFromCart(dest, src, size);
|
pi_dma_from_cart(dest, src, size);
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -191,7 +199,7 @@ void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size) {
|
|||||||
unsigned long newSize = (size + unalignedSrc) + ((size + unalignedSrc) % 2);
|
unsigned long newSize = (size + unalignedSrc) + ((size + unalignedSrc) % 2);
|
||||||
|
|
||||||
unsigned char *buffer = memalign(8, newSize);
|
unsigned char *buffer = memalign(8, newSize);
|
||||||
PI_DMAFromCart(buffer, newSrc, newSize);
|
pi_dma_from_cart(buffer, newSrc, newSize);
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
memcpy(dest, (buffer + unalignedSrc), size);
|
memcpy(dest, (buffer + unalignedSrc), size);
|
||||||
@ -200,7 +208,7 @@ void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getSRAM( uint8_t *buffer, int size){
|
int ed64_ll_get_sram( uint8_t *buffer, int size){
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
io_write(PI_BSD_DOM2_LAT_REG, 0x05);
|
io_write(PI_BSD_DOM2_LAT_REG, 0x05);
|
||||||
@ -210,11 +218,11 @@ int getSRAM( uint8_t *buffer, int size){
|
|||||||
|
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
PI_Init();
|
pi_initialize();
|
||||||
|
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
PI_DMAFromSRAM(buffer, 0, size) ;
|
pi_dma_from_sram(buffer, 0, size) ;
|
||||||
|
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
@ -226,7 +234,7 @@ int getSRAM( uint8_t *buffer, int size){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getEeprom( uint8_t *buffer, int size){
|
int ed64_ll_get_eeprom( uint8_t *buffer, int size){
|
||||||
int blocks=size/8;
|
int blocks=size/8;
|
||||||
for( int b = 0; b < blocks; b++ ) {
|
for( int b = 0; b < blocks; b++ ) {
|
||||||
eeprom_read( b, &buffer[b * 8] );
|
eeprom_read( b, &buffer[b * 8] );
|
||||||
@ -236,11 +244,11 @@ int getEeprom( uint8_t *buffer, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getFlashRAM( uint8_t *buffer, int size){
|
int ed64_ll_get_fram( uint8_t *buffer, int size){
|
||||||
ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2
|
ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
getSRAM(buffer, size);
|
ed64_ll_get_sram(buffer, size);
|
||||||
data_cache_hit_writeback_invalidate(buffer, size);
|
data_cache_hit_writeback_invalidate(buffer, size);
|
||||||
|
|
||||||
dma_wait();
|
dma_wait();
|
||||||
@ -252,31 +260,31 @@ int getFlashRAM( uint8_t *buffer, int size){
|
|||||||
/*
|
/*
|
||||||
sram upload
|
sram upload
|
||||||
*/
|
*/
|
||||||
int setSRAM( uint8_t *buffer, int size){
|
int ed64_ll_set_sram( uint8_t *buffer, int size){
|
||||||
//half working
|
//half working
|
||||||
dma_wait();
|
dma_wait();
|
||||||
//Timing
|
//Timing
|
||||||
PI_Init_SRAM();
|
pi_initialize_sram();
|
||||||
|
|
||||||
//Readmode
|
//Readmode
|
||||||
PI_Init();
|
pi_initialize();
|
||||||
|
|
||||||
data_cache_hit_writeback_invalidate(buffer,size);
|
data_cache_hit_writeback_invalidate(buffer,size);
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
PI_DMAToSRAM(buffer, 0, size);
|
pi_dma_to_sram(buffer, 0, size);
|
||||||
data_cache_hit_writeback_invalidate(buffer,size);
|
data_cache_hit_writeback_invalidate(buffer,size);
|
||||||
|
|
||||||
//Wait
|
//Wait
|
||||||
dma_wait();
|
dma_wait();
|
||||||
//Restore evd Timing
|
//Restore evd Timing
|
||||||
setSDTiming();
|
ed64_ll_set_sdcard_timing();
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int setEeprom(uint8_t *buffer, int size){
|
int ed64_ll_set_eeprom(uint8_t *buffer, int size){
|
||||||
int blocks=size/8;
|
int blocks=size/8;
|
||||||
for( int b = 0; b < blocks; b++ ) {
|
for( int b = 0; b < blocks; b++ ) {
|
||||||
eeprom_write( b, &buffer[b * 8] );
|
eeprom_write( b, &buffer[b * 8] );
|
||||||
@ -285,11 +293,11 @@ int setEeprom(uint8_t *buffer, int size){
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int setFlashRAM(uint8_t *buffer, int size){
|
int ed64_ll_set_fram(uint8_t *buffer, int size){
|
||||||
ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K);
|
ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K);
|
||||||
dma_wait();
|
dma_wait();
|
||||||
|
|
||||||
setSRAM(buffer, size);
|
ed64_ll_set_sram(buffer, size);
|
||||||
data_cache_hit_writeback_invalidate(buffer, size);
|
data_cache_hit_writeback_invalidate(buffer, size);
|
||||||
|
|
||||||
dma_wait();
|
dma_wait();
|
||||||
@ -299,7 +307,7 @@ int setFlashRAM(uint8_t *buffer, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setSDTiming(void){
|
void ed64_ll_set_sdcard_timing(void){
|
||||||
|
|
||||||
io_write(PI_BSD_DOM1_LAT_REG, 0x40);
|
io_write(PI_BSD_DOM1_LAT_REG, 0x40);
|
||||||
io_write(PI_BSD_DOM1_PWD_REG, 0x12);
|
io_write(PI_BSD_DOM1_PWD_REG, 0x12);
|
||||||
|
@ -69,31 +69,15 @@ void ed64_ll_set_ram_bank(uint8_t bank);
|
|||||||
ed64_save_type_t ed64_ll_get_save_type();
|
ed64_save_type_t ed64_ll_get_save_type();
|
||||||
void ed64_ll_set_save_type(ed64_save_type_t type);
|
void ed64_ll_set_save_type(ed64_save_type_t type);
|
||||||
|
|
||||||
|
void ed64_ll_set_sdcard_timing(void);
|
||||||
|
|
||||||
|
int ed64_ll_get_sram( uint8_t *buffer, int size);
|
||||||
|
int ed64_ll_get_eeprom( uint8_t *buffer, int size);
|
||||||
|
int ed64_ll_get_fram( uint8_t *buffer, int size);
|
||||||
|
|
||||||
|
int ed64_ll_set_sram( uint8_t *buffer, int size);
|
||||||
|
int ed64_ll_set_eeprom( uint8_t *buffer, int size);
|
||||||
|
int ed64_ll_set_fram( uint8_t *buffer, int size);
|
||||||
|
|
||||||
/** @} */ /* ed64 */
|
/** @} */ /* ed64 */
|
||||||
|
|
||||||
void data_cache_hit_writeback_invalidate(volatile void *, unsigned long);
|
|
||||||
unsigned int CRC_Calculate(unsigned int crc, unsigned char* buf, unsigned int len);
|
|
||||||
void dma_write_sram(void* src, unsigned long offset, unsigned long size);
|
|
||||||
void dma_read_sram(void *dest, unsigned long offset, unsigned long size);
|
|
||||||
void dma_write_s(void * ram_address, unsigned long pi_address, unsigned long len);
|
|
||||||
void dma_read_s(void * ram_address, unsigned long pi_address, unsigned long len);
|
|
||||||
int writeSram(void* src, unsigned long size);
|
|
||||||
void setSDTiming(void);
|
|
||||||
|
|
||||||
|
|
||||||
void PI_Init(void);
|
|
||||||
void PI_Init_SRAM(void);
|
|
||||||
void PI_DMAFromCart(void* dest, void* src, unsigned long size);
|
|
||||||
void PI_DMAToCart(void* dest, void* src, unsigned long size);
|
|
||||||
void PI_DMAFromSRAM(void *dest, unsigned long offset, unsigned long size);
|
|
||||||
void PI_DMAToSRAM(void* src, unsigned long offset, unsigned long size);
|
|
||||||
void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size);
|
|
||||||
int getSRAM( uint8_t *buffer, int size);
|
|
||||||
int getEeprom( uint8_t *buffer, int size);
|
|
||||||
int getFlashRAM( uint8_t *buffer, int size);
|
|
||||||
int setSRAM( uint8_t *buffer, int size);
|
|
||||||
int setEeprom( uint8_t *buffer, int size);
|
|
||||||
int setFlashRAM( uint8_t *buffer, int size);
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user