Support for composite RBF.

This commit is contained in:
sorgelig
2018-09-29 15:58:23 +08:00
parent f65385d308
commit e7429ec866
4 changed files with 54 additions and 25 deletions

View File

@@ -48,7 +48,15 @@ void FileClose(fileTYPE *file)
int FileOpenEx(fileTYPE *file, const char *name, int mode, char mute)
{
sprintf(full_path, "%s/%s", (mode == -1) ? "" : getRootDir(), name);
const char *root = getRootDir();
if (strncasecmp(getRootDir(), name, strlen(root)))
{
sprintf(full_path, "%s/%s", (mode == -1) ? "" : root, name);
}
else
{
sprintf(full_path, name);
}
FileClose(file);
file->mode = 0;

View File

@@ -491,6 +491,13 @@ int fpga_load_rbf(const char *name, const char *cfg)
}
else
{
void *p = buf;
__off64_t sz = st.st_size;
if (!memcmp(buf, "MiSTer", 6))
{
sz = *(uint32_t*)(((uint8_t*)buf) + 12);
p = (void*)(((uint8_t*)buf) + 16);
}
do_bridge(0);
ret = socfpga_load(buf, st.st_size);
if (ret)

View File

@@ -492,35 +492,38 @@ void user_io_init(const char *path)
}
else
{
// check for multipart rom
sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name());
if (!is_cpc_core() && user_io_file_tx(mainpath))
if (!strlen(path) || !user_io_file_tx(path, 0, 0, 0, 1))
{
sprintf(mainpath, "%s/boot1.rom", user_io_get_core_name());
if (user_io_file_tx(mainpath, 0x40))
// check for multipart rom
sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name());
if (!is_cpc_core() && user_io_file_tx(mainpath))
{
sprintf(mainpath, "%s/boot2.rom", user_io_get_core_name());
if (user_io_file_tx(mainpath, 0x80))
sprintf(mainpath, "%s/boot1.rom", user_io_get_core_name());
if (user_io_file_tx(mainpath, 0x40))
{
sprintf(mainpath, "%s/boot3.rom", user_io_get_core_name());
user_io_file_tx(mainpath, 0xC0);
sprintf(mainpath, "%s/boot2.rom", user_io_get_core_name());
if (user_io_file_tx(mainpath, 0x80))
{
sprintf(mainpath, "%s/boot3.rom", user_io_get_core_name());
user_io_file_tx(mainpath, 0xC0);
}
}
}
}
else
{
// legacy style of rom
sprintf(mainpath, "%s/boot.rom", user_io_get_core_name());
if (!user_io_file_tx(mainpath))
else
{
strcpy(name + strlen(name) - 3, "ROM");
sprintf(mainpath, "%s/%s", get_rbf_dir(), name);
if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath))
// legacy style of rom
sprintf(mainpath, "%s/boot.rom", user_io_get_core_name());
if (!user_io_file_tx(mainpath))
{
if (!user_io_file_tx(name))
strcpy(name + strlen(name) - 3, "ROM");
sprintf(mainpath, "%s/%s", get_rbf_dir(), name);
if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath))
{
sprintf(mainpath, "bootrom/%s", name);
user_io_file_tx(mainpath);
if (!user_io_file_tx(name))
{
sprintf(mainpath, "bootrom/%s", name);
user_io_file_tx(mainpath);
}
}
}
}
@@ -1133,7 +1136,7 @@ static int chr_parse(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const i
return true;
}
static void send_pcolchr(char* name, unsigned char index, int type)
static void send_pcolchr(const char* name, unsigned char index, int type)
{
static char full_path[1024];
@@ -1179,7 +1182,7 @@ static void send_pcolchr(char* name, unsigned char index, int type)
}
}
int user_io_file_tx(char* name, unsigned char index, char opensave, char mute)
int user_io_file_tx(const char* name, unsigned char index, char opensave, char mute, char composite)
{
fileTYPE f = { 0 };
static uint8_t buf[1024];
@@ -1188,6 +1191,17 @@ int user_io_file_tx(char* name, unsigned char index, char opensave, char mute)
unsigned long bytes2send = f.size;
if (composite)
{
if (!FileReadSec(&f, buf)) return 0;
if (memcmp(buf, "MiSTer", 6)) return 0;
uint32_t off = 16 + *(uint32_t*)(((uint8_t*)buf) + 12);
bytes2send -= off;
FileSeek(&f, off, SEEK_SET);
}
/* transmit the entire file using one transfer */
printf("Selected file %s with %lu bytes to send for index %d.%d\n", name, bytes2send, index & 0x3F, index >> 6);

View File

@@ -184,7 +184,7 @@ void user_io_osd_key_enable(char);
void user_io_serial_tx(char *, uint16_t);
char *user_io_8bit_get_string(char);
unsigned long user_io_8bit_set_status(unsigned long, unsigned long);
int user_io_file_tx(char* name, unsigned char index = 0, char opensave = 0, char mute = 0);
int user_io_file_tx(const char* name, unsigned char index = 0, char opensave = 0, char mute = 0, char composite = 0);
int user_io_file_mount(char *name, unsigned char index = 0);
char user_io_dip_switch1(void);
char user_io_serial_status(serial_status_t *, uint8_t);