diff --git a/cheats.cpp b/cheats.cpp index f48a5a7..bfa140f 100644 --- a/cheats.cpp +++ b/cheats.cpp @@ -131,7 +131,7 @@ void cheats_init(const char *rom_path, uint32_t romcrc) // reset cheats user_io_set_index(255); user_io_set_download(1); - user_io_file_tx_write((const uint8_t*)&loaded, 2); + user_io_file_tx_data((const uint8_t*)&loaded, 2); user_io_set_download(0); if (!strcasestr(rom_path, ".zip")) @@ -399,7 +399,7 @@ static void cheats_send() user_io_set_index(255); user_io_set_download(1); - user_io_file_tx_write(buff, pos ? pos : 2); + user_io_file_tx_data(buff, pos ? pos : 2); user_io_set_download(0); } diff --git a/support/arcade/mra_loader.cpp b/support/arcade/mra_loader.cpp index b226535..fbe62ff 100644 --- a/support/arcade/mra_loader.cpp +++ b/support/arcade/mra_loader.cpp @@ -60,7 +60,7 @@ void arcade_sw_send() { user_io_set_index(254); user_io_set_download(1); - user_io_file_tx_write((uint8_t*)&switches.dip_cur, sizeof(switches.dip_cur)); + user_io_file_tx_data((uint8_t*)&switches.dip_cur, sizeof(switches.dip_cur)); user_io_set_download(0); } } @@ -279,7 +279,7 @@ static void rom_finish(int send, uint32_t address) while (romlen[0] > 0) { uint16_t chunk = (romlen[0] > 4096) ? 4096 : romlen[0]; - user_io_file_tx_write(data, chunk); + user_io_file_tx_data(data, chunk); romlen[0] -= chunk; data += chunk; @@ -650,9 +650,9 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons int result = buffer_append(arc_info->data, text); if (result<0) printf("buffer_append failed %d\n",result); - if (result==-1) + if (result==-1) printf("-1 no data given\n"); - if (result==-2) + if (result==-2) printf("-2 could not allocate\n"); } //printf("XML_EVENT_TEXT: text [%s]\n",text); diff --git a/support/megacd/megacd.cpp b/support/megacd/megacd.cpp index 368d5cc..e2ab5af 100644 --- a/support/megacd/megacd.cpp +++ b/support/megacd/megacd.cpp @@ -178,7 +178,7 @@ int mcd_send_data(uint8_t* buf, int len, uint8_t index) { user_io_set_index(index); user_io_set_download(1); - user_io_file_tx_write(buf, len); + user_io_file_tx_data(buf, len); user_io_set_download(0); return 1; } diff --git a/support/neogeo/neogeo_loader.cpp b/support/neogeo/neogeo_loader.cpp index c4d80cb..337bac8 100644 --- a/support/neogeo/neogeo_loader.cpp +++ b/support/neogeo/neogeo_loader.cpp @@ -171,7 +171,7 @@ static uint32_t neogeo_file_tx(const char* path, const char* name, uint8_t neo_f FileReadAdv(&f, buf, chunk); EnableFpga(); - spi8(UIO_FILE_TX_DAT); + spi8(FIO_FILE_TX_DAT); if (neo_file_type == NEO_FILE_RAW) { @@ -405,7 +405,7 @@ static void notify_core(uint8_t index, uint32_t size) if (index == 6) crom_start = 0x300000 + size; EnableFpga(); - spi8(UIO_FILE_TX_DAT); + spi8(FIO_FILE_TX_DAT); spi_w(index); spi_w((uint16_t)size); spi_w(size >> 16); @@ -778,7 +778,7 @@ static void notify_conf() printf("notify_conf(0x%X)\n", conf); EnableFpga(); - spi8(UIO_FILE_TX_DAT); + spi8(FIO_FILE_TX_DAT); spi_w(0x8000); spi_w((uint16_t)conf); spi_w(conf >> 16); diff --git a/support/pcecd/pcecd.cpp b/support/pcecd/pcecd.cpp index 34fbb4d..d51c021 100644 --- a/support/pcecd/pcecd.cpp +++ b/support/pcecd/pcecd.cpp @@ -183,7 +183,7 @@ static int load_bios(char *biosname, const char *cuename) if (!memcmp(buf + i, "ALL DATA", 8)) us_cart = 1; } } - user_io_file_tx_write((uint8_t*)buf, chunk); + user_io_file_tx_data((uint8_t*)buf, chunk); } FileGenerateSavePath(cuename, buf); @@ -248,7 +248,7 @@ void pcecd_set_image(int num, const char *filename) int pcecd_send_data(uint8_t* buf, int len, uint8_t index) { user_io_set_index(index); user_io_set_download(1); - user_io_file_tx_write(buf, len); + user_io_file_tx_data(buf, len); user_io_set_download(0); return 1; } diff --git a/support/st/st_tos.cpp b/support/st/st_tos.cpp index 60a680d..a4d3ad2 100644 --- a/support/st/st_tos.cpp +++ b/support/st/st_tos.cpp @@ -374,7 +374,7 @@ static void fill_tx(uint16_t fill, uint32_t len, int index) len /= 2; EnableFpga(); - spi8(UIO_FILE_TX_DAT); + spi8(FIO_FILE_TX_DAT); while(len--) spi_w(fill); DisableFpga(); @@ -411,7 +411,7 @@ void tos_poll() get_dmastate(); // check the user button - if (!user_io_osd_is_visible() && user_io_user_button()) + if (!user_io_osd_is_visible() && (user_io_user_button() || user_io_get_kbd_reset())) { if (!timer) timer = GetTimer(1000); else if (timer != 1) diff --git a/user_io.cpp b/user_io.cpp index bcc1740..3597134 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -1158,16 +1158,59 @@ static void kbd_fifo_poll() void user_io_set_index(unsigned char index) { EnableFpga(); - spi8(UIO_FILE_INDEX); + spi8(FIO_FILE_INDEX); spi8(index); DisableFpga(); } -void user_io_set_download(unsigned char enable) +void user_io_set_download(unsigned char enable, int addr) { EnableFpga(); - spi8(UIO_FILE_TX); - spi8(enable ? 0xff : 0x00); + spi8(FIO_FILE_TX); + spi8(enable ? 0xff : 0); + if (enable && addr) + { + spi_w(addr); + spi_w(addr >> 16); + } + DisableFpga(); +} + +void user_io_file_tx_data(const uint8_t *addr, uint16_t len) +{ + EnableFpga(); + spi8(FIO_FILE_TX_DAT); + spi_write(addr, len, fio_size); + DisableFpga(); +} + +void user_io_set_upload(unsigned char enable, int addr) +{ + EnableFpga(); + spi8(FIO_FILE_TX); + spi8(enable ? 0xaa : 0); + if (enable && addr) + { + spi_w(addr); + spi_w(addr >> 16); + } + DisableFpga(); +} + +void user_io_file_rx_data(uint8_t *addr, uint16_t len) +{ + EnableFpga(); + spi8(FIO_FILE_TX_DAT); + spi_read(addr, len, fio_size); + DisableFpga(); +} + +void user_io_file_info(const char *ext) +{ + EnableFpga(); + spi8(FIO_FILE_INFO); + spi_w(toupper(ext[0]) << 8 | toupper(ext[1])); + spi_w(toupper(ext[2]) << 8 | toupper(ext[3])); DisableFpga(); } @@ -1532,7 +1575,7 @@ static void send_pcolchr(const char* name, unsigned char index, int type) user_io_set_index(index); user_io_set_download(1); - user_io_file_tx_write(col_attr, type ? 1024 : 1025); + user_io_file_tx_data(col_attr, type ? 1024 : 1025); user_io_set_download(0); } } @@ -1592,14 +1635,6 @@ static void tx_progress(const char* name, unsigned int progress) InfoMessage(progress_buf, 2000, "Loading"); } -void user_io_file_tx_write(const uint8_t *addr, uint16_t len) -{ - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(addr, len, fio_size); - DisableFpga(); -} - static void show_core_info(int info_n) { int i = 2; @@ -1778,11 +1813,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m int len = strlen(f.name); char *p = f.name + len - 4; - EnableFpga(); - spi8(UIO_FILE_INFO); - spi_w(toupper(p[0]) << 8 | toupper(p[1])); - spi_w(toupper(p[2]) << 8 | toupper(p[3])); - DisableFpga(); + user_io_file_info(p); // prepare transmission of new file user_io_set_download(1); @@ -1792,7 +1823,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m printf("Load SNES ROM.\n"); uint8_t* buf = snes_get_header(&f); hexdump(buf, 16, 0); - user_io_file_tx_write(buf, 512); + user_io_file_tx_data(buf, 512); //strip original SNES ROM header if present (not used) if (bytes2send & 512) @@ -1831,7 +1862,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m { uint16_t chunk = (sz > sizeof(buf)) ? sizeof(buf) : sz; FileReadAdv(&fg, buf, chunk); - user_io_file_tx_write(buf, chunk); + user_io_file_tx_data(buf, chunk); sz -= chunk; } FileClose(&fg); @@ -1844,7 +1875,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m uint16_t chunk = (bytes2send > sizeof(buf)) ? sizeof(buf) : bytes2send; FileReadAdv(&f, buf, chunk); - user_io_file_tx_write(buf, chunk); + user_io_file_tx_data(buf, chunk); if (use_progress) { @@ -2028,7 +2059,6 @@ void user_io_send_buttons(char force) //special reset for some cores if (!user_io_osd_is_visible() && (key_map & BUTTON2) && !(map & BUTTON2)) { - if (is_archie()) fpga_load_rbf(name[0] ? name : "Archie.rbf"); if (is_minimig()) minimig_reset(); if (is_megacd()) mcd_reset(); if (is_pce()) pcecd_reset(); @@ -2043,6 +2073,11 @@ void user_io_send_buttons(char force) } } +int user_io_get_kbd_reset() +{ + return kbd_reset; +} + void user_io_set_ini(int ini_num) { const char *name = rbf_path; diff --git a/user_io.h b/user_io.h index f852025..1cc4724 100644 --- a/user_io.h +++ b/user_io.h @@ -67,10 +67,10 @@ #define UIO_SET_AFILTER 0x39 // codes as used by 8bit for file loading from OSD -#define UIO_FILE_TX 0x53 -#define UIO_FILE_TX_DAT 0x54 -#define UIO_FILE_INDEX 0x55 -#define UIO_FILE_INFO 0x56 +#define FIO_FILE_TX 0x53 +#define FIO_FILE_TX_DAT 0x54 +#define FIO_FILE_INDEX 0x55 +#define FIO_FILE_INFO 0x56 // ao486 direct memory access #define UIO_DMA_WRITE 0x61 @@ -190,9 +190,7 @@ void user_io_osd_key_enable(char); void user_io_read_confstr(); char *user_io_get_confstr(int index); uint32_t user_io_8bit_set_status(uint32_t, uint32_t, int ex = 0); -int user_io_file_tx(const char* name, unsigned char index = 0, char opensave = 0, char mute = 0, char composite = 0); -void user_io_file_tx_write(const uint8_t *addr, uint16_t len); -int user_io_get_width(); +int user_io_get_kbd_reset(); uint32_t user_io_get_file_crc(); int user_io_file_mount(const char *name, unsigned char index = 0, char pre = 0); @@ -223,9 +221,15 @@ void user_io_set_ini(int ini_num); void user_io_send_buttons(char); uint16_t user_io_get_sdram_cfg(); -void user_io_set_index(unsigned char index); -void user_io_set_download(unsigned char enable); +int user_io_file_tx(const char* name, unsigned char index = 0, char opensave = 0, char mute = 0, char composite = 0); unsigned char user_io_ext_idx(char *, char*); +void user_io_set_index(unsigned char 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); +void user_io_file_rx_data(uint8_t *addr, uint16_t len); +void user_io_file_info(const char *ext); +int user_io_get_width(); void user_io_check_reset(unsigned short modifiers, char useKeys);