From aedb73aa125946821f2153abde17508d37689a32 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Mon, 9 Dec 2019 07:41:39 +0800 Subject: [PATCH] megacd: support for backup mount/init. --- cheats.cpp | 10 +- support/megacd/megacd.cpp | 430 +++++++++++++++++++++++--------------- support/megacd/megacd.h | 5 +- support/neogeo/loader.cpp | 33 +-- user_io.cpp | 48 +++-- user_io.h | 1 + 6 files changed, 298 insertions(+), 229 deletions(-) diff --git a/cheats.cpp b/cheats.cpp index eebd5fe..63bdd48 100644 --- a/cheats.cpp +++ b/cheats.cpp @@ -353,10 +353,7 @@ static void cheats_send() user_io_set_index(255); // prepare transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); EnableFpga(); spi8(UIO_FILE_TX_DAT); @@ -364,10 +361,7 @@ static void cheats_send() DisableFpga(); // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); + user_io_set_download(0); } void cheats_toggle() diff --git a/support/megacd/megacd.cpp b/support/megacd/megacd.cpp index a16cc3d..590b93c 100644 --- a/support/megacd/megacd.cpp +++ b/support/megacd/megacd.cpp @@ -1,172 +1,258 @@ - -#include -#include -#include -#include - -#include "../../file_io.h" -#include "../../user_io.h" -#include "../../spi.h" -#include "../../hardware.h" -#include "megacd.h" - - -int loaded = 0, unloaded = 0, need_reset=0; -static uint8_t has_command = 0; - -void mcd_poll() -{ - static uint32_t poll_timer = 0, stat_timer = 0; - static uint8_t last_req = 255; - static uint8_t adj = 0; - - if (!stat_timer || CheckTimer(stat_timer)) - { - stat_timer = GetTimer(15); - - if (has_command) { - spi_uio_cmd_cont(UIO_CD_SET); - uint64_t s = cdd.GetStatus(); - spi_w((s >> 0) & 0xFFFF); - spi_w((s >> 16) & 0xFFFF); - spi_w(((s >> 32) & 0x00FF) | (cdd.isData ? 0x01 << 8 : 0x00 << 8)); - DisableIO(); - - has_command = 0; - - //printf("\x1b[32mMCD: Send status, status = %04X%04X%04X, frame = %u\n\x1b[0m", (uint16_t)((s >> 32) & 0x00FF), (uint16_t)((s >> 16) & 0xFFFF), (uint16_t)((s >> 0) & 0xFFFF), frame); - } - - } - - - uint8_t req = spi_uio_cmd_cont(UIO_CD_GET); - if (req != last_req) - { - last_req = req; - - uint16_t data_in[4]; - data_in[0] = spi_w(0); - data_in[1] = spi_w(0); - data_in[2] = spi_w(0); - DisableIO(); - - if (need_reset) { - need_reset = 0; - cdd.Reset(); - } - - uint64_t c = *((uint64_t*)(data_in)); - cdd.SetCommand(c); - cdd.CommandExec(); - has_command = 1; - - - //printf("\x1b[32mMCD: Get command, command = %04X%04X%04X, has_command = %u\n\x1b[0m", data_in[2], data_in[1], data_in[0], has_command); - } - else - DisableIO(); - - if (!poll_timer || CheckTimer(poll_timer)) - { - poll_timer = GetTimer(13 + (!adj ? 1 : 0)); - if (++adj >= 3) adj = 0; - - cdd.Update(); - } -} - - -void mcd_set_image(int num, const char *filename) -{ - (void)num; - - cdd.Unload(); - unloaded = 1; - cdd.status = CD_STAT_OPEN; - - if (*filename) { - - if (cdd.Load(filename) > 0) { - loaded = 1; - cdd.status = cdd.loaded ? CD_STAT_STOP : CD_STAT_NO_DISC; - cdd.latency = 10; - } - else { - cdd.status = CD_STAT_NO_DISC; - } - } -} - -void mcd_reset() { - need_reset = 1; -} - - -int cdd_t::SectorSend(uint8_t* header) -{ - uint8_t buf[2352+2352]; - int len = 2352; - - if (header) { - memcpy(buf + 12, header, 4); - ReadData(buf + 16); - } - else { - len = ReadCDDA(buf); - } - - // set index byte - user_io_set_index(CD_DATA_IO_INDEX); - - // prepare transmission of new file - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write(buf, len, 1); - DisableFpga(); - - // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); - - return 1; -} - - -int cdd_t::SubcodeSend() -{ - uint16_t buf[98/2]; - - ReadSubcode(buf); - - // set index byte - user_io_set_index(CD_SUB_IO_INDEX); - - // prepare transmission of new file - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); - - EnableFpga(); - spi8(UIO_FILE_TX_DAT); - spi_write((uint8_t*)buf, 98, 1); - DisableFpga(); - - // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); - - return 1; -} - - + +#include +#include +#include +#include + +#include "../../file_io.h" +#include "../../user_io.h" +#include "../../spi.h" +#include "../../hardware.h" +#include "megacd.h" + +#define CD_DATA_IO_INDEX 2 +#define CD_SUB_IO_INDEX 3 +#define SAVE_IO_INDEX 5 // fake download to trigger save loading + +int loaded = 0, unloaded = 0, need_reset=0; +static uint8_t has_command = 0; + +void mcd_poll() +{ + static uint32_t poll_timer = 0, stat_timer = 0; + static uint8_t last_req = 255; + static uint8_t adj = 0; + + if (!stat_timer || CheckTimer(stat_timer)) + { + stat_timer = GetTimer(15); + + if (has_command) { + spi_uio_cmd_cont(UIO_CD_SET); + uint64_t s = cdd.GetStatus(); + spi_w((s >> 0) & 0xFFFF); + spi_w((s >> 16) & 0xFFFF); + spi_w(((s >> 32) & 0x00FF) | (cdd.isData ? 0x01 << 8 : 0x00 << 8)); + DisableIO(); + + has_command = 0; + + //printf("\x1b[32mMCD: Send status, status = %04X%04X%04X, frame = %u\n\x1b[0m", (uint16_t)((s >> 32) & 0x00FF), (uint16_t)((s >> 16) & 0xFFFF), (uint16_t)((s >> 0) & 0xFFFF), frame); + } + + } + + + uint8_t req = spi_uio_cmd_cont(UIO_CD_GET); + if (req != last_req) + { + last_req = req; + + uint16_t data_in[4]; + data_in[0] = spi_w(0); + data_in[1] = spi_w(0); + data_in[2] = spi_w(0); + DisableIO(); + + if (need_reset) { + need_reset = 0; + cdd.Reset(); + } + + uint64_t c = *((uint64_t*)(data_in)); + cdd.SetCommand(c); + cdd.CommandExec(); + has_command = 1; + + + //printf("\x1b[32mMCD: Get command, command = %04X%04X%04X, has_command = %u\n\x1b[0m", data_in[2], data_in[1], data_in[0], has_command); + } + else + DisableIO(); + + if (!poll_timer || CheckTimer(poll_timer)) + { + poll_timer = GetTimer(13 + (!adj ? 1 : 0)); + if (++adj >= 3) adj = 0; + + cdd.Update(); + } +} + +static void mcd_mount_save(const char *filename) +{ + user_io_set_index(SAVE_IO_INDEX); + user_io_set_download(1); + + static char name[1024]; + FileGenerateSavePath(filename, name); + user_io_file_mount(name, 0, 1); + + user_io_set_download(0); +} + +void mcd_set_image(int num, const char *filename) +{ + (void)num; + + cdd.Unload(); + unloaded = 1; + cdd.status = CD_STAT_OPEN; + + if (*filename) { + + mcd_mount_save(filename); + + if (cdd.Load(filename) > 0) { + loaded = 1; + cdd.status = cdd.loaded ? CD_STAT_STOP : CD_STAT_NO_DISC; + cdd.latency = 10; + } + else { + cdd.status = CD_STAT_NO_DISC; + } + } +} + +void mcd_reset() { + need_reset = 1; +} + + +int cdd_t::SectorSend(uint8_t* header) +{ + uint8_t buf[2352+2352]; + int len = 2352; + + if (header) { + memcpy(buf + 12, header, 4); + ReadData(buf + 16); + } + else { + len = ReadCDDA(buf); + } + + // set index byte + user_io_set_index(CD_DATA_IO_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_set_download(0); + return 1; +} + + +int cdd_t::SubcodeSend() +{ + uint16_t buf[98/2]; + + ReadSubcode(buf); + + // set index byte + user_io_set_index(CD_SUB_IO_INDEX); + + // prepare transmission of new file + user_io_set_download(1); + + EnableFpga(); + spi8(UIO_FILE_TX_DAT); + spi_write((uint8_t*)buf, 98, 1); + DisableFpga(); + + // signal end of transmission + user_io_set_download(0); + return 1; +} + +static char int_blank[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x40, + 0x00, 0x7D, 0x00, 0x7D, 0x00, 0x7D, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x53, 0x45, 0x47, 0x41, 0x5F, 0x43, 0x44, 0x5F, 0x52, 0x4F, 0x4D, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x52, 0x41, 0x4D, 0x5F, 0x43, 0x41, 0x52, 0x54, 0x52, 0x49, 0x44, 0x47, 0x45, 0x5F, 0x5F, 0x5F, +}; + +static char ext_blank[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x40, + 0x1F, 0xFD, 0x1F, 0xFD, 0x1F, 0xFD, 0x1F, 0xFD, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x53, 0x45, 0x47, 0x41, 0x5F, 0x43, 0x44, 0x5F, 0x52, 0x4F, 0x4D, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x52, 0x41, 0x4D, 0x5F, 0x43, 0x41, 0x52, 0x54, 0x52, 0x49, 0x44, 0x47, 0x45, 0x5F, 0x5F, 0x5F, +}; + +void mcd_fill_blanksave(uint8_t *buffer, uint32_t lba) +{ + if (lba == 0xF) + { + memcpy(buffer, int_blank, 512); + } + else if (lba == 0x40F) + { + memcpy(buffer, ext_blank, 512); + } + else + { + memset(buffer, 0, 512); + } +} diff --git a/support/megacd/megacd.h b/support/megacd/megacd.h index 7053172..e474007 100644 --- a/support/megacd/megacd.h +++ b/support/megacd/megacd.h @@ -104,10 +104,6 @@ private: #define CD_SCAN_SPEED 30 -#define CD_DATA_IO_INDEX 2 -#define CD_SUB_IO_INDEX 3 - - //cdd.cpp extern cdd_t cdd; extern uint32_t frame; @@ -116,5 +112,6 @@ extern uint32_t frame; void mcd_poll(); void mcd_set_image(int num, const char *filename); void mcd_reset(); +void mcd_fill_blanksave(uint8_t *buffer, uint32_t lba); #endif diff --git a/support/neogeo/loader.cpp b/support/neogeo/loader.cpp index cb546d6..da10c21 100644 --- a/support/neogeo/loader.cpp +++ b/support/neogeo/loader.cpp @@ -160,10 +160,7 @@ static uint32_t neogeo_file_tx(const char* path, const char* name, uint8_t neo_f user_io_set_index(index); // prepare transmission of new file - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); int progress = -1; @@ -209,11 +206,7 @@ static uint32_t neogeo_file_tx(const char* path, const char* name, uint8_t neo_f FileClose(&f); // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); - + user_io_set_download(0); return size; } @@ -400,11 +393,7 @@ static uint32_t crom_start = 0; static void notify_core(uint8_t index, uint32_t size) { user_io_set_index(10); - - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); if (index == 4 || index == 6) size = (size + ALIGN_1MB) & ~ALIGN_1MB; char memcp = !(index == 9 || (index >= 16 && index < 64)); @@ -424,10 +413,7 @@ static void notify_core(uint8_t index, uint32_t size) spi_w(0); DisableFpga(); - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); + user_io_set_download(0); } static uint32_t crom_sz = 0; @@ -786,11 +772,7 @@ static uint32_t set_config(uint32_t new_config, uint32_t mask) static void notify_conf() { user_io_set_index(10); - - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); uint32_t conf = set_config(0, 0); printf("notify_conf(0x%X)\n", conf); @@ -804,10 +786,7 @@ static void notify_conf() spi_w(0); DisableFpga(); - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); + user_io_set_download(0); } #define VROM_SIZE (16 * 1024 * 1024) diff --git a/user_io.cpp b/user_io.cpp index 89328ec..9901ffa 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -1185,6 +1185,14 @@ void user_io_set_index(unsigned char index) DisableFpga(); } +void user_io_set_download(unsigned char enable) +{ + EnableFpga(); + spi8(UIO_FILE_TX); + spi8(enable ? 0xff : 0x00); + DisableFpga(); +} + int user_io_file_mount(char *name, unsigned char index, char pre) { int writable = 0; @@ -1529,11 +1537,7 @@ static void send_pcolchr(const char* name, unsigned char index, int type) //hexdump(col_attr, sizeof(col_attr)); user_io_set_index(index); - - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); EnableFpga(); spi8(UIO_FILE_TX_DAT); @@ -1541,10 +1545,7 @@ static void send_pcolchr(const char* name, unsigned char index, int type) DisableFpga(); // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); + user_io_set_download(0); } } @@ -1638,10 +1639,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m DisableFpga(); // prepare transmission of new file - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0xff); - DisableFpga(); + user_io_set_download(1); if (is_snes_core() && bytes2send) { @@ -1714,10 +1712,7 @@ int user_io_file_tx(const char* name, unsigned char index, char opensave, char m } // signal end of transmission - EnableFpga(); - spi8(UIO_FILE_TX); - spi8(0x00); - DisableFpga(); + user_io_set_download(0); printf("\n"); if (is_zx81_core() && index) @@ -2518,7 +2513,24 @@ void user_io_poll() //Even after error we have to provide the block to the core //Give an empty block. - if (!done) memset(buffer[disk], (sd_image[disk].type == 2) ? -1 : 0, sizeof(buffer[disk])); + if (!done) + { + if (sd_image[disk].type == 2) + { + if (is_megacd_core()) + { + mcd_fill_blanksave(buffer[disk], lba); + } + else + { + memset(buffer[disk], -1, sizeof(buffer[disk])); + } + } + else + { + memset(buffer[disk], 0, sizeof(buffer[disk])); + } + } buffer_lba[disk] = lba; } diff --git a/user_io.h b/user_io.h index 8be3102..82a6e2b 100644 --- a/user_io.h +++ b/user_io.h @@ -244,6 +244,7 @@ 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); unsigned char user_io_ext_idx(char *, char*); void user_io_check_reset(unsigned short modifiers, char useKeys);