diff --git a/src/flashcart/ed64/ed64.c b/src/flashcart/ed64/ed64.c index 7338786b..049058eb 100644 --- a/src/flashcart/ed64/ed64.c +++ b/src/flashcart/ed64/ed64.c @@ -59,6 +59,9 @@ static flashcart_err_t ed64_init (void) { current_state.is_fram_save_type = false; ed64_state_save(¤t_state); } + else if (save_size > KiB(32)) { // sram 128 + ed64_ll_get_sram(cartsave_data, save_size); + } else if (save_size > KiB(2)) { // sram ed64_ll_get_sram(cartsave_data, save_size); } @@ -237,8 +240,9 @@ static flashcart_err_t ed64_load_save (char *save_path) { ed64_ll_set_eeprom(cartsave_data, save_size); break; case SAVE_TYPE_SRAM: - case SAVE_TYPE_SRAM_128K: ed64_ll_set_sram(cartsave_data, save_size); + case SAVE_TYPE_SRAM_128K: + ed64_ll_set_sram_128(cartsave_data, save_size); break; case SAVE_TYPE_FLASHRAM: ed64_ll_set_fram(cartsave_data, save_size); diff --git a/src/flashcart/ed64/ed64_ll.c b/src/flashcart/ed64/ed64_ll.c index 8ab3fe28..2c00d731 100644 --- a/src/flashcart/ed64/ed64_ll.c +++ b/src/flashcart/ed64/ed64_ll.c @@ -222,7 +222,7 @@ void pi_dma_from_cart_safe (void *dest, void *src, unsigned long size) { } -int ed64_ll_get_sram (uint8_t *buffer, int size) { +int ed64_ll_get_sram_128 (uint8_t *buffer, int size) { dma_wait(); @@ -250,6 +250,35 @@ int ed64_ll_get_sram (uint8_t *buffer, int size) { } + +int ed64_ll_get_sram (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); + + dma_wait(); + + pi_initialize(); + + dma_wait(); + + pi_dma_from_sram(buffer, 0, 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); + + return 1; + +} + int ed64_ll_get_eeprom (uint8_t *buffer, int size) { int blocks=size/8; @@ -267,7 +296,7 @@ int ed64_ll_get_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); //2 dma_wait(); - ed64_ll_get_sram(buffer, size); + ed64_ll_get_sram_128(buffer, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); @@ -282,6 +311,32 @@ sram upload */ +int ed64_ll_set_sram_128 (uint8_t *buffer, int size) { + + //half working + dma_wait(); + //Timing + pi_initialize_sram(); + + //Readmode + pi_initialize(); + + data_cache_hit_writeback_invalidate(buffer,size); + dma_wait(); + + pi_dma_to_sram(buffer, 0 - (KiB(64) - size), size); + data_cache_hit_writeback_invalidate(buffer,size); + + //Wait + dma_wait(); + //Restore evd Timing + ed64_ll_set_sdcard_timing(); + + return 1; + +} + + int ed64_ll_set_sram (uint8_t *buffer, int size) { //half working @@ -295,7 +350,7 @@ int ed64_ll_set_sram (uint8_t *buffer, int size) { data_cache_hit_writeback_invalidate(buffer,size); dma_wait(); - pi_dma_to_sram(buffer, 0 - (KiB(64) - size), size); + pi_dma_to_sram(buffer, 0, size); data_cache_hit_writeback_invalidate(buffer,size); //Wait @@ -324,7 +379,7 @@ int ed64_ll_set_fram (uint8_t *buffer, int size) { ed64_ll_set_save_type(SAVE_TYPE_SRAM_128K); dma_wait(); - ed64_ll_set_sram(buffer, size); + ed64_ll_set_sram_128(buffer, size); data_cache_hit_writeback_invalidate(buffer, size); dma_wait(); diff --git a/src/flashcart/ed64/ed64_ll.h b/src/flashcart/ed64/ed64_ll.h index 2d1c84e8..0f36618d 100644 --- a/src/flashcart/ed64/ed64_ll.h +++ b/src/flashcart/ed64/ed64_ll.h @@ -69,10 +69,12 @@ void ed64_ll_set_sram_bank (uint8_t bank); ed64_save_type_t ed64_ll_get_save_type (); void ed64_ll_set_save_type (ed64_save_type_t type); +int ed64_ll_get_sram_128 (uint8_t *buffer, int size); 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_128 (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);