From e7429ec8662b60e3cc094d0c08919c2962d5bfba Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sat, 29 Sep 2018 15:58:23 +0800 Subject: [PATCH] Support for composite RBF. --- file_io.cpp | 10 ++++++++- fpga_io.cpp | 7 +++++++ user_io.cpp | 60 +++++++++++++++++++++++++++++++++-------------------- user_io.h | 2 +- 4 files changed, 54 insertions(+), 25 deletions(-) diff --git a/file_io.cpp b/file_io.cpp index ea5efa6..9c05728 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -48,7 +48,15 @@ void FileClose(fileTYPE *file) int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute) { - sprintf(full_path, "%s/%s", (mode == -1) ? "" : getRootDir(), name); + const char *root = getRootDir(); + if (strncasecmp(getRootDir(), name, strlen(root))) + { + sprintf(full_path, "%s/%s", (mode == -1) ? "" : root, name); + } + else + { + sprintf(full_path, name); + } FileClose(file); file->mode = 0; diff --git a/fpga_io.cpp b/fpga_io.cpp index e2b9cfd..a4ee7bc 100644 --- a/fpga_io.cpp +++ b/fpga_io.cpp @@ -491,6 +491,13 @@ int fpga_load_rbf(const char *name, const char *cfg) } else { + void *p = buf; + __off64_t sz = st.st_size; + if (!memcmp(buf, "MiSTer", 6)) + { + sz = *(uint32_t*)(((uint8_t*)buf) + 12); + p = (void*)(((uint8_t*)buf) + 16); + } do_bridge(0); ret = socfpga_load(buf, st.st_size); if (ret) diff --git a/user_io.cpp b/user_io.cpp index 79ba449..c689545 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -492,35 +492,38 @@ void user_io_init(const char *path) } else { - // check for multipart rom - sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name()); - if (!is_cpc_core() && user_io_file_tx(mainpath)) + if (!strlen(path) || !user_io_file_tx(path, 0, 0, 0, 1)) { - sprintf(mainpath, "%s/boot1.rom", user_io_get_core_name()); - if (user_io_file_tx(mainpath, 0x40)) + // check for multipart rom + sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name()); + if (!is_cpc_core() && user_io_file_tx(mainpath)) { - sprintf(mainpath, "%s/boot2.rom", user_io_get_core_name()); - if (user_io_file_tx(mainpath, 0x80)) + sprintf(mainpath, "%s/boot1.rom", user_io_get_core_name()); + if (user_io_file_tx(mainpath, 0x40)) { - sprintf(mainpath, "%s/boot3.rom", user_io_get_core_name()); - user_io_file_tx(mainpath, 0xC0); + sprintf(mainpath, "%s/boot2.rom", user_io_get_core_name()); + if (user_io_file_tx(mainpath, 0x80)) + { + sprintf(mainpath, "%s/boot3.rom", user_io_get_core_name()); + user_io_file_tx(mainpath, 0xC0); + } } } - } - else - { - // legacy style of rom - sprintf(mainpath, "%s/boot.rom", user_io_get_core_name()); - if (!user_io_file_tx(mainpath)) + else { - strcpy(name + strlen(name) - 3, "ROM"); - sprintf(mainpath, "%s/%s", get_rbf_dir(), name); - if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath)) + // legacy style of rom + sprintf(mainpath, "%s/boot.rom", user_io_get_core_name()); + if (!user_io_file_tx(mainpath)) { - if (!user_io_file_tx(name)) + strcpy(name + strlen(name) - 3, "ROM"); + sprintf(mainpath, "%s/%s", get_rbf_dir(), name); + if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath)) { - sprintf(mainpath, "bootrom/%s", name); - user_io_file_tx(mainpath); + if (!user_io_file_tx(name)) + { + sprintf(mainpath, "bootrom/%s", name); + user_io_file_tx(mainpath); + } } } } @@ -1133,7 +1136,7 @@ static int chr_parse(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const i return true; } -static void send_pcolchr(char* name, unsigned char index, int type) +static void send_pcolchr(const char* name, unsigned char index, int type) { static char full_path[1024]; @@ -1179,7 +1182,7 @@ static void send_pcolchr(char* name, unsigned char index, int type) } } -int user_io_file_tx(char* name, unsigned char index, char opensave, char mute) +int user_io_file_tx(const char* name, unsigned char index, char opensave, char mute, char composite) { fileTYPE f = { 0 }; static uint8_t buf[1024]; @@ -1188,6 +1191,17 @@ int user_io_file_tx(char* name, unsigned char index, char opensave, char mute) unsigned long bytes2send = f.size; + if (composite) + { + if (!FileReadSec(&f, buf)) return 0; + if (memcmp(buf, "MiSTer", 6)) return 0; + + uint32_t off = 16 + *(uint32_t*)(((uint8_t*)buf) + 12); + bytes2send -= off; + + FileSeek(&f, off, SEEK_SET); + } + /* transmit the entire file using one transfer */ printf("Selected file %s with %lu bytes to send for index %d.%d\n", name, bytes2send, index & 0x3F, index >> 6); diff --git a/user_io.h b/user_io.h index a4711d8..8ed6433 100644 --- a/user_io.h +++ b/user_io.h @@ -184,7 +184,7 @@ void user_io_osd_key_enable(char); void user_io_serial_tx(char *, uint16_t); char *user_io_8bit_get_string(char); unsigned long user_io_8bit_set_status(unsigned long, unsigned long); -int user_io_file_tx(char* name, unsigned char index = 0, char opensave = 0, char mute = 0); +int user_io_file_tx(const char* name, unsigned char index = 0, char opensave = 0, char mute = 0, char composite = 0); int user_io_file_mount(char *name, unsigned char index = 0); char user_io_dip_switch1(void); char user_io_serial_status(serial_status_t *, uint8_t);