From 7080eb13622051cb4a814aade8091caaf8c10caa Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 18 Dec 2019 06:13:20 +0800 Subject: [PATCH] gba: add goomba emulator autoloading for gb/gbc roms. --- cheats.cpp | 9 +------ support/arcade/romutils.cpp | 6 +---- support/megacd/megacd.cpp | 9 +------ user_io.cpp | 54 +++++++++++++++++++++++++------------ user_io.h | 1 + 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/cheats.cpp b/cheats.cpp index 63bdd48..5ca8350 100644 --- a/cheats.cpp +++ b/cheats.cpp @@ -352,15 +352,8 @@ static void cheats_send() user_io_set_index(255); - // prepare transmission user_io_set_download(1); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(buff, pos ? pos : 2, fpga_get_fio_size()); - DisableFpga(); - - // signal end of transmission + user_io_file_tx_write(buff, pos ? pos : 2); user_io_set_download(0); } diff --git a/support/arcade/romutils.cpp b/support/arcade/romutils.cpp index 001c49d..51eb3d1 100644 --- a/support/arcade/romutils.cpp +++ b/support/arcade/romutils.cpp @@ -65,11 +65,7 @@ static int file_tx_start(unsigned char index) static int file_tx_data(const uint8_t *buf, uint16_t chunk, struct MD5Context *md5context) { - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - - spi_write(buf, chunk, user_io_get_width()); - DisableFpga(); + user_io_file_tx_write(buf, chunk); if (md5context) MD5Update(md5context, buf, chunk); #if DEBUG_ROM_BINARY diff --git a/support/megacd/megacd.cpp b/support/megacd/megacd.cpp index 5edd7cc..6270e84 100644 --- a/support/megacd/megacd.cpp +++ b/support/megacd/megacd.cpp @@ -115,15 +115,8 @@ int mcd_send_data(uint8_t* buf, int len, uint8_t index) { // set index byte user_io_set_index(index); - // prepare transmission of new file user_io_set_download(1); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(buf, len, 1); - DisableFpga(); - - // signal end of transmission + user_io_file_tx_write(buf, len); user_io_set_download(0); return 1; } diff --git a/user_io.cpp b/user_io.cpp index c57501d..a4c2349 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -1552,14 +1552,9 @@ static void send_pcolchr(const char* name, unsigned char index, int type) //hexdump(col_attr, sizeof(col_attr)); user_io_set_index(index); + user_io_set_download(1); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(col_attr, type ? 1024 : 1025, fio_size); - DisableFpga(); - - // signal end of transmission + user_io_file_tx_write(col_attr, type ? 1024 : 1025); user_io_set_download(0); } } @@ -1619,6 +1614,14 @@ 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(); +} + int user_io_file_tx(const char* name, unsigned char index, char opensave, char mute, char composite) { fileTYPE f = {}; @@ -1661,10 +1664,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); - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(buf, 512, fio_size); - DisableFpga(); + user_io_file_tx_write(buf, 512); //strip original SNES ROM header if present (not used) if (bytes2send & 512) @@ -1682,16 +1682,36 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m int progress = -1; if (use_progress) MenuHide(); - while (bytes2send) + int dosend = 1; + if (!strcasecmp(core_name, "GBA") && ((index >> 6) == 1 || (index >> 6) == 2)) + { + fileTYPE fg = {}; + if (!FileOpen(&fg, user_io_make_filepath(HomeDir, "goomba.rom"))) + { + dosend = 0; + Info("Cannot open goomba.rom!"); + sleep(1); + } + else + { + uint32_t sz = fg.size; + while (sz) + { + uint16_t chunk = (sz > sizeof(buf)) ? sizeof(buf) : sz; + FileReadAdv(&fg, buf, chunk); + user_io_file_tx_write(buf, chunk); + sz -= chunk; + } + FileClose(&fg); + } + } + + while (dosend && bytes2send) { uint16_t chunk = (bytes2send > sizeof(buf)) ? sizeof(buf) : bytes2send; FileReadAdv(&f, buf, chunk); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(buf, chunk, fio_size); - DisableFpga(); + user_io_file_tx_write(buf, chunk); if (use_progress) { diff --git a/user_io.h b/user_io.h index 52d2c75..7d97b40 100644 --- a/user_io.h +++ b/user_io.h @@ -210,6 +210,7 @@ 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(); uint32_t user_io_get_file_crc();