From 5c916b75670d36949a27ca1a49f5ff002669708a Mon Sep 17 00:00:00 2001 From: sorgelig Date: Tue, 4 Jul 2017 15:40:40 +0800 Subject: [PATCH] Multiple sector-based files access for multiple disk drives emulation. --- menu.c | 9 +++-- user_io.c | 113 +++++++++++++++++++++++++++++++----------------------- user_io.h | 2 +- 3 files changed, 72 insertions(+), 52 deletions(-) diff --git a/menu.c b/menu.c index c01a1eb..927eb79 100644 --- a/menu.c +++ b/menu.c @@ -531,6 +531,7 @@ void HandleUI(void) static long helptext_timer; static const char *helptext; static char helpstate = 0; + static char drive_num = 0; uint8_t keys[6] = { 0,0,0,0,0,0 }; uint16_t keys_ps2[6] = { 0,0,0,0,0,0 }; @@ -849,7 +850,7 @@ void HandleUI(void) unsigned long status = user_io_8bit_set_status(0, 0); // 0,0 gets status p = user_io_8bit_get_string(i); - printf("Option %d: %s\n", i-1, p); + //printf("Option %d: %s\n", i-1, p); // check for 'F'ile or 'S'D image strings if (p && ((p[0] == 'F') || (p[0] == 'S'))) { @@ -1020,6 +1021,8 @@ void HandleUI(void) } else if ((p[0] == 'F') || (p[0] == 'S')) { + drive_num = 0; + if (p[1] >= '0' && p[1] <= '3') drive_num = p[1] - '0'; static char ext[13]; substrcpy(ext, p, 1); while (strlen(ext) < 3) strcat(ext, " "); @@ -1069,7 +1072,7 @@ void HandleUI(void) case MENU_8BIT_MAIN_IMAGE_SELECTED: iprintf("Image selected: %s\n", SelectedPath); user_io_set_index(user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1)); - user_io_file_mount(SelectedPath); + user_io_file_mount(drive_num, SelectedPath); menustate = MENU_NONE1; break; @@ -3257,7 +3260,7 @@ void HandleUI(void) *s2++ = 0; OsdWrite(4, s, 0, 0); OsdWrite(5, "", 0, 0); - OsdWrite(6, " Change FPGA core", menusub == 0, 0); + OsdWrite(6, " Change FPGA core", menusub == 0, 0); for (int i = 7; i < OsdGetSize() - 1; i++) OsdWrite(i, "", 0, 0); OsdWrite(OsdGetSize() - 1, STD_EXIT, menusub == 1, 0); menustate = MENU_FIRMWARE2; diff --git a/user_io.c b/user_io.c index e70a997..362d069 100644 --- a/user_io.c +++ b/user_io.c @@ -29,7 +29,7 @@ unsigned char key_remap_table[MAX_REMAP][2]; #define BREAK 0x8000 -fileTYPE sd_image; +fileTYPE sd_image[4] = { 0 }; // mouse and keyboard emulation state static emu_mode_t emu_mode = EMU_NONE; @@ -75,7 +75,7 @@ void user_io_init() { // no sd card image selected, SD card accesses will go directly // to the card - sd_image.size = 0; + memset(sd_image, 0, sizeof(sd_image)); // mark remap table as unused memset(key_remap_table, 0, sizeof(key_remap_table)); @@ -249,10 +249,11 @@ void user_io_detect_core_type() // check if there's a .vhd present sprintf(mainpath, "%s/boot.vhd", user_io_get_core_name()); - if (!user_io_file_mount(mainpath)) + user_io_set_index(0); + if (!user_io_file_mount(0, mainpath)) { strcpy(name + strlen(name) - 3, "VHD"); - user_io_file_mount(name); + user_io_file_mount(0, name); } } @@ -414,9 +415,9 @@ static uint8_t CID[16] = { 0x3e, 0x00, 0x00, 0x34, 0x38, 0x32, 0x44, 0x00, 0x00, // set SD card info in FPGA (CSD, CID) void user_io_sd_set_config(void) { - CSD[6] = (uint8_t)(sd_image.size >> 9); - CSD[7] = (uint8_t)(sd_image.size >> 17); - CSD[8] = (uint8_t)(sd_image.size >> 25); + CSD[6] = (uint8_t)(sd_image[0].size >> 9); + CSD[7] = (uint8_t)(sd_image[0].size >> 17); + CSD[8] = (uint8_t)(sd_image[0].size >> 25); // forward it to the FPGA spi_uio_cmd_cont(UIO_SET_SDCONF); @@ -582,39 +583,39 @@ void user_io_set_index(unsigned char index) DisableFpga(); } -int user_io_file_mount(char *name) +int user_io_file_mount(int num, char *name) { int writable = FileCanWrite(name); - int ret = FileOpenEx(&sd_image, name, writable ? (O_RDWR | O_SYNC) : O_RDONLY); + int ret = FileOpenEx(&sd_image[num], name, writable ? (O_RDWR | O_SYNC) : O_RDONLY); if (!ret) { - sd_image.size = 0; + sd_image[num].size = 0; printf("Failed to open file %s\n", name); return 0; } - printf("Mount %s as %s\n", name, writable ? "read-write" : "read-only"); + printf("Mount %s as %s on %d slot\n", name, writable ? "read-write" : "read-only", num); // send mounted image size first then notify about mounting EnableIO(); spi8(UIO_SET_SDINFO); if (io_ver) { - spi_w((uint16_t)(sd_image.size)); - spi_w((uint16_t)(sd_image.size>>16)); - spi_w((uint16_t)(sd_image.size>>32)); - spi_w((uint16_t)(sd_image.size>>48)); + spi_w((uint16_t)(sd_image[num].size)); + spi_w((uint16_t)(sd_image[num].size>>16)); + spi_w((uint16_t)(sd_image[num].size>>32)); + spi_w((uint16_t)(sd_image[num].size>>48)); } else { - spi32le(sd_image.size); - spi32le(sd_image.size>>32); + spi32le(sd_image[num].size); + spi32le(sd_image[num].size>>32); } DisableIO(); // notify core of possible sd image change - spi_uio_cmd8(UIO_SET_SDSTAT, 0); + spi_uio_cmd8(UIO_SET_SDSTAT, 1<