diff --git a/menu.cpp b/menu.cpp index 97c2ef8..f035146 100644 --- a/menu.cpp +++ b/menu.cpp @@ -873,11 +873,11 @@ void HandleUI(void) OsdWrite(0, "", 0, 0); strcpy(s, " Floppy 0: "); - strncat(s, archie_get_floppy_name(0),27); + strncat(s, get_image_name(0) ? get_image_name(0) : "* no disk *",27); OsdWrite(1, s, menusub == 0, 0); strcpy(s, " Floppy 1: "); - strncat(s, archie_get_floppy_name(1), 27); + strncat(s, get_image_name(1) ? get_image_name(1) : "* no disk *", 27); OsdWrite(2, s, menusub == 1, 0); OsdWrite(3, "", 0, 0); @@ -921,12 +921,7 @@ void HandleUI(void) switch (menusub) { case 0: // Floppy 0 case 1: // Floppy 1 - if (archie_floppy_is_inserted(menusub)) { - archie_set_floppy(menusub, NULL); - menustate = MENU_ARCHIE_MAIN1; - } - else - SelectFile("ADF", SCANO_DIR, MENU_ARCHIE_MAIN_FILE_SELECTED, MENU_ARCHIE_MAIN1); + SelectFile("ADF", SCANO_DIR | SCANO_UMOUNT, MENU_ARCHIE_MAIN_FILE_SELECTED, MENU_ARCHIE_MAIN1); break; case 2: // Load ROM @@ -967,8 +962,8 @@ void HandleUI(void) break; case MENU_ARCHIE_MAIN_FILE_SELECTED: // file successfully selected - if (menusub == 0) archie_set_floppy(0, SelectedPath); - if (menusub == 1) archie_set_floppy(1, SelectedPath); + if (menusub == 0) user_io_file_mount(SelectedPath, 0); + if (menusub == 1) user_io_file_mount(SelectedPath, 1); if (menusub == 2) archie_set_rom(SelectedPath); menustate = MENU_ARCHIE_MAIN1; break; diff --git a/support/archie/archie.cpp b/support/archie/archie.cpp index d9ee417..3fb6f47 100644 --- a/support/archie/archie.cpp +++ b/support/archie/archie.cpp @@ -7,8 +7,6 @@ #include "../../debug.h" #include "../../user_io.h" -#define MAX_FLOPPY 4 - #define CONFIG_FILENAME "ARCHIE.CFG" typedef struct @@ -19,14 +17,6 @@ typedef struct static archie_config_t config; -fileTYPE floppy[MAX_FLOPPY] = {}; - -#define ARCHIE_FILE_TX 0x53 -#define ARCHIE_FILE_TX_DAT 0x54 -#define ARCHIE_FDC_GET_STATUS 0x55 -#define ARCHIE_FDC_TX_DATA 0x56 -#define ARCHIE_FDC_SET_STATUS 0x57 - #define archie_debugf(a, ...) printf("\033[1;31mARCHIE: " a "\033[0m\n", ##__VA_ARGS__) // #define archie_debugf(a, ...) #define archie_x_debugf(a, ...) printf("\033[1;32mARCHIE: " a "\033[0m\n", ##__VA_ARGS__) @@ -73,8 +63,6 @@ static unsigned char flags; static unsigned long hold_off_timer; #endif -static uint8_t sector_buffer[1024]; - const char *archie_get_rom_name(void) { char *p = strrchr(config.rom_img, '/'); @@ -83,16 +71,6 @@ const char *archie_get_rom_name(void) return p; } -const char *archie_get_floppy_name(int i) -{ - if (!floppy[i].size) return "* no disk *"; - - char *p = strrchr(floppy[i].name, '/'); - if (!p) p = floppy[i].name; else p++; - - return p; -} - void archie_set_ar(char i) { if (i) config.system_ctrl |= 1; @@ -121,89 +99,6 @@ void archie_save_config(void) FileSaveConfig(CONFIG_FILENAME, &config, sizeof(config)); } -void archie_send_file(unsigned char id, char *name) -{ - archie_debugf("Sending file with id %d", id); - - fileTYPE file = {}; - if (!FileOpen(&file, name)) return; - - // prepare transmission of new file - EnableFpga(); - spi8(ARCHIE_FILE_TX); - spi8(id); - DisableFpga(); - - unsigned long time = GetTimer(0); - - printf("["); - - unsigned short i, blocks = file.size / 512; - for (i = 0; i> 20); - - // signal end of transmission - EnableFpga(); - spi8(ARCHIE_FILE_TX); - spi8(0x00); - DisableFpga(); -} - -void archie_fdc_set_status(void) -{ - int i; - - // send status bytes for all four possible floppies - EnableFpga(); - spi8(ARCHIE_FDC_SET_STATUS); - for (i = 0; i> 4; - int side = (status[2] & 0x80) ? 0 : 1; - int track = status[2] & 0x7f; - int sector = status[3] & 0x0f; - unsigned long lba = 2 * (10 * track + 5 * side + sector); - int floppy_index = -1; - - // allow only single floppy drives to be selected - int i; - for (i = 0; i %ld", floppy_index, side, track, sector, lba); - - if (!f->size) archie_x_debugf("DIO: floppy not inserted. Core should not do this!!"); - else { - DISKLED_ON; - // read two consecutive sectors - FileSeekLBA(f, lba); - FileReadAdv(f, buffer, 1024); - - EnableFpga(); - spi8(ARCHIE_FDC_TX_DATA); - spi_write(buffer, 1024, 0); - DisableFpga(); - DISKLED_OFF; - } - } - } - } - } - } -} - -void archie_poll(void) -{ - archie_handle_kbd(); - archie_handle_fdc(); -} diff --git a/support/archie/archie.h b/support/archie/archie.h index ddee96e..74d0973 100644 --- a/support/archie/archie.h +++ b/support/archie/archie.h @@ -8,10 +8,7 @@ void archie_poll(void); void archie_kbd(unsigned short code); void archie_mouse(unsigned char b, int16_t x, int16_t y); const char *archie_get_rom_name(void); -const char *archie_get_floppy_name(int b); void archie_set_rom(char *); -void archie_set_floppy(int i, char *); -char archie_floppy_is_inserted(int i); void archie_save_config(void); void archie_set_ar(char i); diff --git a/user_io.cpp b/user_io.cpp index a71eab0..86a3e5d 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -64,6 +64,16 @@ static bool scrl_status = 0; static char minimig_adjust = 0; +const char *get_image_name(int i) +{ + if (!sd_image[i].size) return NULL; + + char *p = strrchr(sd_image[i].name, '/'); + if (!p) p = sd_image[i].name; else p++; + + return p; +} + static uint32_t uart_mode; uint32_t user_io_get_uart_mode() { @@ -1670,143 +1680,113 @@ void user_io_poll() { DisableIO(); } + } - // sd card emulation - if (is_x86_core()) - { - x86_poll(); - } - else - { - static uint8_t buffer[4][512]; - uint32_t lba; - uint16_t c = user_io_sd_get_status(&lba); - //if(c&3) printf("user_io_sd_get_status: cmd=%02x, lba=%08x\n", c, lba); + // sd card emulation + if (is_x86_core()) + { + x86_poll(); + } + else if (core_type == CORE_TYPE_8BIT || core_type == CORE_TYPE_ARCHIE) + { + static uint8_t buffer[4][512]; + uint32_t lba; + uint16_t c = user_io_sd_get_status(&lba); + //if(c&3) printf("user_io_sd_get_status: cmd=%02x, lba=%08x\n", c, lba); - // valid sd commands start with "5x" to avoid problems with - // cores that don't implement this command - if ((c & 0xf0) == 0x50) + // valid sd commands start with "5x" to avoid problems with + // cores that don't implement this command + if ((c & 0xf0) == 0x50) + { + // check if core requests configuration + if (c & 0x08) { - // check if core requests configuration - if (c & 0x08) - { - printf("core requests SD config\n"); - user_io_sd_set_config(); - } + printf("core requests SD config\n"); + user_io_sd_set_config(); + } - if(c & 0x3802) - { - int disk = 3; - if (c & 0x0002) disk = 0; - else if (c & 0x0800) disk = 1; - else if (c & 0x1000) disk = 2; + if(c & 0x3802) + { + int disk = 3; + if (c & 0x0002) disk = 0; + else if (c & 0x0800) disk = 1; + else if (c & 0x1000) disk = 2; - // only write if the inserted card is not sdhc or - // if the core uses sdhc - if(c & 0x04) + // only write if the inserted card is not sdhc or + // if the core uses sdhc + if(c & 0x04) + { + //printf("SD WR %d on %d\n", lba, disk); + + int done = 0; + buffer_lba[disk] = lba; + + // Fetch sector data from FPGA ... + spi_uio_cmd_cont(UIO_SECTOR_WR); + spi_block_read(buffer[disk], fio_size); + DisableIO(); + + + if (sd_image[disk].type == 2 && !lba) { - //printf("SD WR %d on %d\n", lba, disk); - - int done = 0; - buffer_lba[disk] = lba; - - // Fetch sector data from FPGA ... - spi_uio_cmd_cont(UIO_SECTOR_WR); - spi_block_read(buffer[disk], fio_size); - DisableIO(); - - - if (sd_image[disk].type == 2 && !lba) + //Create the file + if (FileOpenEx(&sd_image[disk], sd_image[disk].path, O_CREAT | O_RDWR | O_SYNC)) { - //Create the file - if (FileOpenEx(&sd_image[disk], sd_image[disk].path, O_CREAT | O_RDWR | O_SYNC)) + diskled_on(); + if (FileWriteSec(&sd_image[disk], buffer[disk])) { - diskled_on(); - if (FileWriteSec(&sd_image[disk], buffer[disk])) - { - sd_image[disk].size = 512; - done = 1; - } - } - else - { - printf("Error in creating file: %s\n", sd_image[disk].path); + sd_image[disk].size = 512; + done = 1; } } else { - // ... and write it to disk - __off64_t size = sd_image[disk].size>>9; - if (size && size>=lba) - { - diskled_on(); - if (FileSeekLBA(&sd_image[disk], lba)) - { - if (FileWriteSec(&sd_image[disk], buffer[disk])) - { - done = 1; - if (size == lba) - { - size++; - sd_image[disk].size = size << 9; - } - } - } - } + printf("Error in creating file: %s\n", sd_image[disk].path); } - - if (!done) buffer_lba[disk] = -1; } - } - else - if (c & 0x0701) - { - int disk = 3; - if (c & 0x0001) disk = 0; - else if (c & 0x0100) disk = 1; - else if (c & 0x0200) disk = 2; - - //printf("SD RD %d on %d\n", lba, disk); - - int done = 0; - - if (buffer_lba[disk] != lba) + else { - if (sd_image[disk].size) + // ... and write it to disk + __off64_t size = sd_image[disk].size>>9; + if (size && size>=lba) { diskled_on(); if (FileSeekLBA(&sd_image[disk], lba)) { - if (FileReadSec(&sd_image[disk], buffer[disk])) + if (FileWriteSec(&sd_image[disk], buffer[disk])) { done = 1; + if (size == lba) + { + size++; + sd_image[disk].size = size << 9; + } } } } - - //Even after error we have to provide the block to the core - //Give an empty block. - if (!done) memset(buffer[disk], 0, sizeof(buffer[disk])); - buffer_lba[disk] = lba; } - if(buffer_lba[disk] == lba) - { - //hexdump(buffer, 32, 0); + if (!done) buffer_lba[disk] = -1; + } + } + else + if (c & 0x0701) + { + int disk = 3; + if (c & 0x0001) disk = 0; + else if (c & 0x0100) disk = 1; + else if (c & 0x0200) disk = 2; - // data is now stored in buffer. send it to fpga - spi_uio_cmd_cont(UIO_SECTOR_RD); - spi_block_write(buffer[disk], fio_size); - DisableIO(); - } + //printf("SD RD %d on %d, WIDE=%d\n", lba, disk, fio_size); - // just load the next sector now, so it may be prefetched - // for the next request already - done = 0; + int done = 0; + + if (buffer_lba[disk] != lba) + { if (sd_image[disk].size) { diskled_on(); - if (FileSeekLBA(&sd_image[disk], lba + 1)) + if (FileSeekLBA(&sd_image[disk], lba)) { if (FileReadSec(&sd_image[disk], buffer[disk])) { @@ -1814,22 +1794,55 @@ void user_io_poll() } } } - if(done) buffer_lba[disk] = lba + 1; - if (sd_image[disk].type == 2) + //Even after error we have to provide the block to the core + //Give an empty block. + if (!done) memset(buffer[disk], 0, sizeof(buffer[disk])); + buffer_lba[disk] = lba; + } + + if(buffer_lba[disk] == lba) + { + //hexdump(buffer, 32, 0); + + // data is now stored in buffer. send it to fpga + spi_uio_cmd_cont(UIO_SECTOR_RD); + spi_block_write(buffer[disk], fio_size); + DisableIO(); + } + + // just load the next sector now, so it may be prefetched + // for the next request already + done = 0; + if (sd_image[disk].size) + { + diskled_on(); + if (FileSeekLBA(&sd_image[disk], lba + 1)) { - buffer_lba[disk] = -1; + if (FileReadSec(&sd_image[disk], buffer[disk])) + { + done = 1; + } } } - } + if(done) buffer_lba[disk] = lba + 1; - if(diskled_is_on && CheckTimer(diskled_timer)) - { - DISKLED_OFF; - diskled_is_on = 0; + if (sd_image[disk].type == 2) + { + buffer_lba[disk] = -1; + } } } + if(diskled_is_on && CheckTimer(diskled_timer)) + { + DISKLED_OFF; + diskled_is_on = 0; + } + } + + if (core_type == CORE_TYPE_8BIT) + { // frequently check ps2 mouse for events if (CheckTimer(mouse_timer)) { diff --git a/user_io.h b/user_io.h index 9a5bb55..1caa51c 100644 --- a/user_io.h +++ b/user_io.h @@ -182,7 +182,6 @@ char is_archie(); char is_sharpmz(); void user_io_poll(); char user_io_menu_button(); -char user_io_button_dip_switch1(); char user_io_user_button(); void user_io_osd_key_enable(char); void user_io_serial_tx(char *, uint16_t); @@ -198,6 +197,8 @@ char is_x86_core(); char is_snes_core(); char has_menu(); +const char *get_image_name(int i); + int user_io_get_kbdemu(); uint32_t user_io_get_uart_mode();