diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 14d9c8b8..caf0a0cb 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -67,8 +67,9 @@ static flashcart_err_t ed64_init (void) { // everdrive doesn't care about the save type other than eeprom // so we can just check the size - - if (save_size > KiB(2)) { + if (save_size == KiB(128)) { + getFlashRAM(cartsave_data, save_size); + } else if (save_size > KiB(2)) { getSRAM(cartsave_data, save_size); } else { getEeprom(cartsave_data, save_size); @@ -212,7 +213,11 @@ static flashcart_err_t ed64_load_save (char *save_path) { // everdrive doesnt care about the save type other than eeprom // so we can just check the size - if (save_size >= KiB(32)) { //sram and flash + if (save_size == KiB(128)) { //sram 128 and flash + setFlashRAM(cartsave_data, save_size); + } + + else if (save_size > KiB(2)) { //sram setSRAM(cartsave_data, save_size); } diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 0fba27ae..64a4f09c 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -119,22 +119,22 @@ void ed64_ll_set_sram_bank(uint8_t bank) { void PI_Init(void) { PI_DMAWait(); - IO_WRITE(PI_STATUS_REG, 0x03); + io_write(PI_STATUS_REG, 0x03); } // Inits PI for sram transfer void PI_Init_SRAM(void) { - IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x05); - IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x0C); - IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x0D); - IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x02); + io_write(PI_BSD_DOM2_LAT_REG, 0x05); + io_write(PI_BSD_DOM2_PWD_REG, 0x0C); + io_write(PI_BSD_DOM2_PGS_REG, 0x0D); + io_write(PI_BSD_DOM2_RLS_REG, 0x02); } void PI_DMAWait(void) { - while (IO_READ(PI_STATUS_REG) & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)); + while (io_read(PI_STATUS_REG) & (PI_STATUS_IO_BUSY | PI_STATUS_DMA_BUSY)); } @@ -142,10 +142,10 @@ void PI_DMAWait(void) { void PI_DMAFromSRAM(void *dest, unsigned long offset, unsigned long size) { - IO_WRITE(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - IO_WRITE(PI_CART_ADDR_REG, (0xA8000000 + offset)); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); + io_write(PI_CART_ADDR_REG, (0xA8000000 + offset)); asm volatile ("" : : : "memory"); - IO_WRITE(PI_WR_LEN_REG, (size - 1)); + io_write(PI_WR_LEN_REG, (size - 1)); asm volatile ("" : : : "memory"); } @@ -154,29 +154,29 @@ void PI_DMAFromSRAM(void *dest, unsigned long offset, unsigned long size) { void PI_DMAToSRAM(void *src, unsigned long offset, unsigned long size) { //void* PI_DMAWait(); - IO_WRITE(PI_STATUS_REG, 2); - IO_WRITE(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - IO_WRITE(PI_CART_ADDR_REG, (0xA8000000 + offset)); - IO_WRITE(PI_RD_LEN_REG, (size - 1)); + io_write(PI_STATUS_REG, 2); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); + io_write(PI_CART_ADDR_REG, (0xA8000000 + offset)); + io_write(PI_RD_LEN_REG, (size - 1)); } void PI_DMAFromCart(void* dest, void* src, unsigned long size) { PI_DMAWait(); - IO_WRITE(PI_STATUS_REG, 0x03); - IO_WRITE(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); - IO_WRITE(PI_CART_ADDR_REG, K0_TO_PHYS(src)); - IO_WRITE(PI_WR_LEN_REG, (size - 1)); + io_write(PI_STATUS_REG, 0x03); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(dest)); + io_write(PI_CART_ADDR_REG, K0_TO_PHYS(src)); + io_write(PI_WR_LEN_REG, (size - 1)); } void PI_DMAToCart(void* dest, void* src, unsigned long size) { PI_DMAWait(); - IO_WRITE(PI_STATUS_REG, 0x02); - IO_WRITE(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); - IO_WRITE(PI_CART_ADDR_REG, K0_TO_PHYS(dest)); - IO_WRITE(PI_RD_LEN_REG, (size - 1)); + io_write(PI_STATUS_REG, 0x02); + io_write(PI_DRAM_ADDR_REG, K1_TO_PHYS(src)); + io_write(PI_CART_ADDR_REG, K0_TO_PHYS(dest)); + io_write(PI_RD_LEN_REG, (size - 1)); } @@ -211,10 +211,10 @@ void PI_SafeDMAFromCart(void *dest, void *src, unsigned long size) { int getSRAM( uint8_t *buffer, int size){ dma_wait(); - IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x05); - IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x0C); - IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x0D); - IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x02); + io_write(PI_BSD_DOM2_LAT_REG, 0x05); + io_write(PI_BSD_DOM2_PWD_REG, 0x0C); + io_write(PI_BSD_DOM2_PGS_REG, 0x0D); + io_write(PI_BSD_DOM2_RLS_REG, 0x02); dma_wait(); @@ -226,10 +226,10 @@ int getSRAM( uint8_t *buffer, int size){ dma_wait(); - IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x40); - IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x12); - IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x07); - IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x03); + io_write(PI_BSD_DOM2_LAT_REG, 0x40); + io_write(PI_BSD_DOM2_PWD_REG, 0x12); + io_write(PI_BSD_DOM2_PGS_REG, 0x07); + io_write(PI_BSD_DOM2_RLS_REG, 0x03); return 1; } @@ -244,6 +244,19 @@ int getEeprom( uint8_t *buffer, int size){ } +int getFlashRAM( uint8_t *buffer, int size){ + ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 + PI_DMAWait(); + + getSRAM(buffer, size); + data_cache_hit_writeback_invalidate(buffer, size); + + PI_DMAWait(); + ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); + + return 1; +} + /* sram upload */ @@ -279,30 +292,44 @@ int setEeprom(uint8_t *buffer, int size){ return 1; } +int setFlashRAM(uint8_t *buffer, int size){ + ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 + PI_DMAWait(); + + setSRAM(buffer, size); + data_cache_hit_writeback_invalidate(buffer, size); + + PI_DMAWait(); + ed64_ll_set_save_type(SAVE_TYPE_FLASHRAM); + + return 1; +} + + void setSDTiming(void){ // PI_DMAWait(); - IO_WRITE(PI_BSD_DOM1_LAT_REG, 0x40); - IO_WRITE(PI_BSD_DOM1_PWD_REG, 0x12); - IO_WRITE(PI_BSD_DOM1_PGS_REG, 0x07); - IO_WRITE(PI_BSD_DOM1_RLS_REG, 0x03); + io_write(PI_BSD_DOM1_LAT_REG, 0x40); + io_write(PI_BSD_DOM1_PWD_REG, 0x12); + io_write(PI_BSD_DOM1_PGS_REG, 0x07); + io_write(PI_BSD_DOM1_RLS_REG, 0x03); - IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x40); - IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x12); - IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x07); - IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x03); + io_write(PI_BSD_DOM2_LAT_REG, 0x40); + io_write(PI_BSD_DOM2_PWD_REG, 0x12); + io_write(PI_BSD_DOM2_PGS_REG, 0x07); + io_write(PI_BSD_DOM2_RLS_REG, 0x03); } void restoreTiming(void) { //n64 timing restore :> - IO_WRITE(PI_BSD_DOM1_LAT_REG, 0x40); - IO_WRITE(PI_BSD_DOM1_PWD_REG, 0x12); - IO_WRITE(PI_BSD_DOM1_PGS_REG, 0x07); - IO_WRITE(PI_BSD_DOM1_RLS_REG, 0x03); + io_write(PI_BSD_DOM1_LAT_REG, 0x40); + io_write(PI_BSD_DOM1_PWD_REG, 0x12); + io_write(PI_BSD_DOM1_PGS_REG, 0x07); + io_write(PI_BSD_DOM1_RLS_REG, 0x03); - IO_WRITE(PI_BSD_DOM2_LAT_REG, 0x40); - IO_WRITE(PI_BSD_DOM2_PWD_REG, 0x12); - IO_WRITE(PI_BSD_DOM2_PGS_REG, 0x07); - IO_WRITE(PI_BSD_DOM2_RLS_REG, 0x03); + io_write(PI_BSD_DOM2_LAT_REG, 0x40); + io_write(PI_BSD_DOM2_PWD_REG, 0x12); + io_write(PI_BSD_DOM2_PGS_REG, 0x07); + io_write(PI_BSD_DOM2_RLS_REG, 0x03); } diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 2561b489..42156faf 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -92,8 +92,10 @@ 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 diff --git a/src/menu/cart_load.c b/src/menu/cart_load.c index 2986d9a2..6f24d07a 100644 --- a/src/menu/cart_load.c +++ b/src/menu/cart_load.c @@ -1,5 +1,6 @@ #include +#include #include #include "cart_load.h" @@ -174,7 +175,7 @@ cart_load_err_t cart_load_emulator (menu_t *menu, cart_load_emu_type_t emu_type, save_type = FLASHCART_SAVE_TYPE_FLASHRAM; break; case CART_LOAD_EMU_TYPE_GAMEBOY_COLOR: - path_push(path, "gbc.v64"); + path_push(path, "gbc.v64"); save_type = FLASHCART_SAVE_TYPE_FLASHRAM; break; case CART_LOAD_EMU_TYPE_SEGA_GENERIC_8BIT: