From 52076b908b7fd200c7096f680bef264baa7d58b1 Mon Sep 17 00:00:00 2001 From: Marcoen Hirschberg Date: Fri, 15 Dec 2023 18:35:57 +0100 Subject: [PATCH] N64: support fast ROM loading (#862) Normal ROM loading is still supported to not break older versions of the core. --- menu.cpp | 2 +- support/n64/n64.cpp | 22 +++++++++++++++++++--- support/n64/n64.h | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/menu.cpp b/menu.cpp index 032b311..b82f561 100644 --- a/menu.cpp +++ b/menu.cpp @@ -2422,7 +2422,7 @@ void HandleUI(void) } else if (is_n64()) { - if (!n64_rom_tx(selPath, idx)) Info("failed to load ROM"); + if (!n64_rom_tx(selPath, idx, load_addr)) Info("failed to load ROM"); } else { diff --git a/support/n64/n64.cpp b/support/n64/n64.cpp index 4ea34f3..09ddc7c 100644 --- a/support/n64/n64.cpp +++ b/support/n64/n64.cpp @@ -2,6 +2,7 @@ #include "n64_cpak_header.h" #include "../../menu.h" #include "../../user_io.h" +#include "../../shmem.h" #include #include @@ -1043,7 +1044,7 @@ static void unmount_all_save_files() mounted_save_files = 0; } -int n64_rom_tx(const char *name, unsigned char idx) { +int n64_rom_tx(const char *name, unsigned char idx, uint32_t load_addr) { static uint8_t buf[4096]; fileTYPE f; @@ -1058,7 +1059,7 @@ int n64_rom_tx(const char *name, unsigned char idx) { user_io_set_index(idx); // prepare transmission of new file - user_io_set_download(1); + user_io_set_download(1, load_addr ? data_size : 0); const int use_progress = 1; if (use_progress) ProgressMessage(0, 0, 0, 0); @@ -1107,6 +1108,9 @@ int n64_rom_tx(const char *name, unsigned char idx) { MD5Context ctx; MD5Init(&ctx); + uint8_t *mem = load_addr ? (uint8_t *)shmem_map(fpga_mem(load_addr), data_size) : nullptr; + uint8_t *write_ptr = mem; + while (data_left) { size_t chunk = (data_left > sizeof(buf)) ? sizeof(buf) : data_left; @@ -1181,13 +1185,25 @@ int n64_rom_tx(const char *name, unsigned char idx) { } } - user_io_file_tx_data(buf, chunk); + // copy to DDR memory for fast ROM loading + if (write_ptr) + { + memcpy(write_ptr, buf, chunk); + write_ptr += chunk; + } + else + { + user_io_file_tx_data(buf, chunk); + } if (use_progress) ProgressMessage("Loading", f.name, data_size - data_left, data_size); data_left -= chunk; is_first_chunk = false; } + if (mem) + shmem_unmap(mem, data_size); + MD5Final(md5, &ctx); md5_to_hex(md5, md5_hex); printf("File MD5: %s\n", md5_hex); diff --git a/support/n64/n64.h b/support/n64/n64.h index b6f2c03..0407369 100644 --- a/support/n64/n64.h +++ b/support/n64/n64.h @@ -4,7 +4,7 @@ #include #include "../../file_io.h" -int n64_rom_tx(const char* name, unsigned char index); +int n64_rom_tx(const char* name, unsigned char index, uint32_t load_addr); void n64_load_savedata(uint64_t lba, int ack, uint64_t& buffer_lba, uint8_t* buffer, uint32_t buffer_size, uint32_t blksz, uint32_t sz); void n64_save_savedata(uint64_t lba, int ack, uint64_t& buffer_lba, uint8_t* buffer, uint32_t blksz, uint32_t sz);