From 65afb152a0eb32a111c3a4ba9883c3b7e9bf210f Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 21 Aug 2020 21:38:02 +0800 Subject: [PATCH] Support for supplement file loading. --- menu.cpp | 148 ++++++++++++++++++++++++++++++++++++++-------------- user_io.cpp | 62 ++++++++++++++++++++++ user_io.h | 2 + 3 files changed, 172 insertions(+), 40 deletions(-) diff --git a/menu.cpp b/menu.cpp index 3163837..3da618b 100644 --- a/menu.cpp +++ b/menu.cpp @@ -836,6 +836,47 @@ static void vga_nag() EnableOsd_on(OSD_ALL); } +void process_addon(char *ext, uint8_t idx) +{ + static char name[1024]; + + while (*ext && *ext != ',') ext++; + if (*ext) ext++; + if (!*ext) return; + + printf("addons: %s\n", ext); + + int i = 0; + while (1) + { + char *fname = name; + strcpy(name, selPath); + char *p = strrchr(name, '.'); + if (!p) p = name + strlen(name); + *p++ = '.'; + + substrcpy(p, ext, i); + if (!strlen(p)) return; + if (*p == '!') + { + *p = 0; + char *bs = strrchr(name, '/'); + if (!bs) + { + fname = p + 1; + } + else + { + strcpy(bs + 1, p + 1); + } + } + + printf("Trying: %s\n", fname); + user_io_file_tx_a(fname, ((i+1) << 8) | idx); + i++; + } +} + static int joymap_first = 0; static int wm_x = 0; @@ -886,6 +927,7 @@ void HandleUI(void) static int menusub_parent = 0; static char title[32] = {}; static uint32_t saved_menustate = 0; + static char addon[1024]; static char cp_MenuCancel; @@ -1736,6 +1778,8 @@ void HandleUI(void) uint32_t entry = 0; int i = 1; + addon[0] = 0; + while (1) { p = user_io_get_confstr(i++); @@ -1775,8 +1819,18 @@ void HandleUI(void) } if (!inpage || h || p[0] < 'A') continue; + + // supplement files + if (p[0] == 'f') + { + strcpy(addon, p); + continue; + } + if (entry == menusub) break; entry++; + + if (p[0] == 'F' || p[0] == 'S') addon[0] = 0; } if (!d) @@ -1957,56 +2011,70 @@ void HandleUI(void) break; case MENU_8BIT_MAIN_FILE_SELECTED: - MenuHide(); - printf("File selected: %s\n", selPath); - memcpy(Selected_F[ioctl_index & 15], selPath, sizeof(Selected_F[ioctl_index & 15])); + { + MenuHide(); + printf("File selected: %s\n", selPath); + memcpy(Selected_F[ioctl_index & 15], selPath, sizeof(Selected_F[ioctl_index & 15])); - if (fs_Options & SCANO_NEOGEO) - { - neogeo_romset_tx(selPath); - } - else - { - if (is_pce()) + char idx = user_io_ext_idx(selPath, fs_pFileExt) << 6 | ioctl_index; + if (addon[0] == 'f' && addon[1] != '1') process_addon(addon, idx); + + if (fs_Options & SCANO_NEOGEO) { - pcecd_set_image(0, ""); - pcecd_reset(); + neogeo_romset_tx(selPath); + } + else + { + if (is_pce()) + { + pcecd_set_image(0, ""); + pcecd_reset(); + } + user_io_store_filename(selPath); + user_io_file_tx(selPath, idx, opensave); + if (user_io_use_cheats()) cheats_init(selPath, user_io_get_file_crc()); } - user_io_store_filename(selPath); - user_io_file_tx(selPath, user_io_ext_idx(selPath, fs_pFileExt) << 6 | ioctl_index, opensave); - if (user_io_use_cheats()) cheats_init(selPath, user_io_get_file_crc()); - } - recent_update(SelectedDir, Selected_F[ioctl_index & 15], SelectedLabel, ioctl_index); + if (addon[0] == 'f' && addon[1] == '1') process_addon(addon, idx); + + recent_update(SelectedDir, Selected_F[ioctl_index & 15], SelectedLabel, ioctl_index); + } break; case MENU_8BIT_MAIN_IMAGE_SELECTED: - menustate = selPath[0] ? MENU_NONE1 : MENU_8BIT_MAIN1; - HandleUI(); + { + menustate = selPath[0] ? MENU_NONE1 : MENU_8BIT_MAIN1; + HandleUI(); - printf("Image selected: %s\n", selPath); - memcpy(Selected_S[ioctl_index & 3], selPath, sizeof(Selected_S[ioctl_index & 3])); + printf("Image selected: %s\n", selPath); + memcpy(Selected_S[ioctl_index & 3], selPath, sizeof(Selected_S[ioctl_index & 3])); - if (is_x86()) - { - x86_set_image(ioctl_index, selPath); - } - else if (is_megacd()) - { - mcd_set_image(ioctl_index, selPath); - } - else if (is_pce()) - { - pcecd_set_image(ioctl_index, selPath); - cheats_init(selPath, 0); - } - else - { - user_io_set_index(user_io_ext_idx(selPath, fs_pFileExt) << 6 | (menusub + 1)); - user_io_file_mount(selPath, ioctl_index); - } + char idx = user_io_ext_idx(selPath, fs_pFileExt) << 6 | ioctl_index; + if (addon[0] == 'f' && addon[1] != '1') process_addon(addon, idx); - recent_update(SelectedDir, Selected_S[ioctl_index & 3], SelectedLabel, ioctl_index + 500); + if (is_x86()) + { + x86_set_image(ioctl_index, selPath); + } + else if (is_megacd()) + { + mcd_set_image(ioctl_index, selPath); + } + else if (is_pce()) + { + pcecd_set_image(ioctl_index, selPath); + cheats_init(selPath, 0); + } + else + { + user_io_set_index(user_io_ext_idx(selPath, fs_pFileExt) << 6 | (menusub + 1)); + user_io_file_mount(selPath, ioctl_index); + } + + if (addon[0] == 'f' && addon[1] == '1') process_addon(addon, idx); + + recent_update(SelectedDir, Selected_S[ioctl_index & 3], SelectedLabel, ioctl_index + 500); + } break; case MENU_8BIT_SYSTEM1: diff --git a/user_io.cpp b/user_io.cpp index 3597134..dc087db 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -1163,6 +1163,14 @@ void user_io_set_index(unsigned char index) DisableFpga(); } +void user_io_set_aindex(uint16_t index) +{ + EnableFpga(); + spi8(FIO_FILE_INDEX); + spi_w(index); + DisableFpga(); +} + void user_io_set_download(unsigned char enable, int addr) { EnableFpga(); @@ -1785,6 +1793,60 @@ static int process_ss(const char *rom_name) return 1; } +int user_io_file_tx_a(const char* name, uint16_t index) +{ + fileTYPE f = {}; + static uint8_t buf[4096]; + + if (!FileOpen(&f, name, 1)) return 0; + + unsigned long bytes2send = f.size; + + /* transmit the entire file using one transfer */ + printf("Addon file %s with %lu bytes to send for index %04X\n", name, bytes2send, index); + + // set index byte (0=bios rom, 1-n=OSD entry index) + user_io_set_aindex(index); + + // prepare transmission of new file + user_io_set_download(1); + + int use_progress = 1; + int size = bytes2send; + int progress = -1; + if (use_progress) MenuHide(); + + while (bytes2send) + { + uint16_t chunk = (bytes2send > sizeof(buf)) ? sizeof(buf) : bytes2send; + + FileReadAdv(&f, buf, chunk); + user_io_file_tx_data(buf, chunk); + + if (use_progress) + { + int new_progress = PROGRESS_MAX - ((((uint64_t)bytes2send)*PROGRESS_MAX) / size); + if (progress != new_progress) + { + progress = new_progress; + tx_progress(f.name, progress); + } + } + bytes2send -= chunk; + } + + // check if core requests some change while downloading + check_status_change(); + + printf("Done.\n"); + FileClose(&f); + + // signal end of transmission + user_io_set_download(0); + MenuHide(); + return 1; +} + int user_io_file_tx(const char* name, unsigned char index, char opensave, char mute, char composite) { fileTYPE f = {}; diff --git a/user_io.h b/user_io.h index 1cc4724..f8b03c8 100644 --- a/user_io.h +++ b/user_io.h @@ -222,8 +222,10 @@ void user_io_send_buttons(char); uint16_t user_io_get_sdram_cfg(); 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_tx_a(const char* name, uint16_t index); unsigned char user_io_ext_idx(char *, char*); void user_io_set_index(unsigned char index); +void user_io_set_aindex(uint16_t index); void user_io_set_download(unsigned char enable, int addr = 0); void user_io_file_tx_data(const uint8_t *addr, uint16_t len); void user_io_set_upload(unsigned char enable, int addr = 0);