Support for *.sav files.
This commit is contained in:
21
menu.cpp
21
menu.cpp
@@ -646,6 +646,7 @@ void HandleUI(void)
|
||||
|
||||
struct RigidDiskBlock *rdb;
|
||||
|
||||
static char opensave;
|
||||
char *p;
|
||||
char s[40];
|
||||
unsigned char m, up, down, select, menu, right, left, plus, minus;
|
||||
@@ -1141,6 +1142,7 @@ void HandleUI(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
static char ext[13];
|
||||
char fs_present;
|
||||
p = user_io_8bit_get_string(1);
|
||||
fs_present = p && strlen(p);
|
||||
@@ -1159,21 +1161,24 @@ void HandleUI(void)
|
||||
if(!menusub && fs_present)
|
||||
{
|
||||
// use a local copy of "p" since SelectFile will destroy the buffer behind it
|
||||
static char ext[13];
|
||||
strncpy(ext, p, 13);
|
||||
while (strlen(ext) < 3) strcat(ext, " ");
|
||||
SelectFile(ext, SCAN_DIR, MENU_8BIT_MAIN_FILE_SELECTED, MENU_8BIT_MAIN1, 1);
|
||||
}
|
||||
else if ((p[0] == 'F') || (p[0] == 'S'))
|
||||
else if (p[0] == 'F')
|
||||
{
|
||||
opensave = (p[1] == 'S');
|
||||
substrcpy(ext, p, 1);
|
||||
while (strlen(ext) < 3) strcat(ext, " ");
|
||||
SelectFile(ext, SCAN_DIR, MENU_8BIT_MAIN_FILE_SELECTED, MENU_8BIT_MAIN1, 1);
|
||||
}
|
||||
else if (p[0] == 'S')
|
||||
{
|
||||
drive_num = 0;
|
||||
if (p[1] >= '0' && p[1] <= '3') drive_num = p[1] - '0';
|
||||
static char ext[13];
|
||||
substrcpy(ext, p, 1);
|
||||
while (strlen(ext) < 3) strcat(ext, " ");
|
||||
SelectFile(ext, SCAN_DIR | ((p[0] == 'S') ? SCAN_UMOUNT : 0),
|
||||
(p[0] == 'F') ? MENU_8BIT_MAIN_FILE_SELECTED : MENU_8BIT_MAIN_IMAGE_SELECTED,
|
||||
MENU_8BIT_MAIN1, 1);
|
||||
SelectFile(ext, SCAN_DIR | SCAN_UMOUNT, MENU_8BIT_MAIN_IMAGE_SELECTED, MENU_8BIT_MAIN1, 1);
|
||||
}
|
||||
else if (p[0] == 'O')
|
||||
{
|
||||
@@ -1230,7 +1235,7 @@ void HandleUI(void)
|
||||
|
||||
case MENU_8BIT_MAIN_FILE_SELECTED:
|
||||
printf("File selected: %s\n", SelectedPath);
|
||||
user_io_file_tx(SelectedPath, user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1));
|
||||
user_io_file_tx(SelectedPath, user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1), opensave);
|
||||
menustate = MENU_NONE1;
|
||||
break;
|
||||
|
||||
@@ -1243,7 +1248,7 @@ void HandleUI(void)
|
||||
else
|
||||
{
|
||||
user_io_set_index(user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1));
|
||||
user_io_file_mount(drive_num, SelectedPath);
|
||||
user_io_file_mount(SelectedPath, drive_num);
|
||||
}
|
||||
menustate = SelectedPath[0] ? MENU_NONE1 : MENU_8BIT_MAIN1;
|
||||
break;
|
||||
|
||||
55
user_io.cpp
55
user_io.cpp
@@ -480,7 +480,7 @@ void user_io_init(const char *path)
|
||||
{
|
||||
// check for multipart rom
|
||||
sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name());
|
||||
if (user_io_file_tx(mainpath, 0))
|
||||
if (user_io_file_tx(mainpath))
|
||||
{
|
||||
sprintf(mainpath, "%s/boot1.rom", user_io_get_core_name());
|
||||
if (user_io_file_tx(mainpath, 0x40))
|
||||
@@ -497,16 +497,16 @@ void user_io_init(const char *path)
|
||||
{
|
||||
// legacy style of rom
|
||||
sprintf(mainpath, "%s/boot.rom", user_io_get_core_name());
|
||||
if (!user_io_file_tx(mainpath, 0))
|
||||
if (!user_io_file_tx(mainpath))
|
||||
{
|
||||
strcpy(name + strlen(name) - 3, "ROM");
|
||||
sprintf(mainpath, "%s/%s", get_rbf_dir(), name);
|
||||
if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath, 0))
|
||||
if (!get_rbf_dir()[0] || !user_io_file_tx(mainpath))
|
||||
{
|
||||
if (!user_io_file_tx(name, 0))
|
||||
if (!user_io_file_tx(name))
|
||||
{
|
||||
sprintf(mainpath, "bootrom/%s", name);
|
||||
user_io_file_tx(mainpath, 0);
|
||||
user_io_file_tx(mainpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -515,13 +515,13 @@ void user_io_init(const char *path)
|
||||
// check if vhd present
|
||||
sprintf(mainpath, "%s/boot.vhd", user_io_get_core_name());
|
||||
user_io_set_index(0);
|
||||
if (!user_io_file_mount(0, mainpath))
|
||||
if (!user_io_file_mount(mainpath))
|
||||
{
|
||||
strcpy(name + strlen(name) - 3, "VHD");
|
||||
sprintf(mainpath, "%s/%s", get_rbf_dir(), name);
|
||||
if (!get_rbf_dir()[0] || !user_io_file_mount(0, mainpath))
|
||||
if (!get_rbf_dir()[0] || !user_io_file_mount(mainpath))
|
||||
{
|
||||
user_io_file_mount(0, name);
|
||||
user_io_file_mount(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -814,30 +814,30 @@ void user_io_set_index(unsigned char index)
|
||||
DisableFpga();
|
||||
}
|
||||
|
||||
int user_io_file_mount(int num, char *name)
|
||||
int user_io_file_mount(char *name, unsigned char index)
|
||||
{
|
||||
int writable = 0;
|
||||
int ret = 0;
|
||||
if (x2trd_ext_supp(name))
|
||||
{
|
||||
ret = x2trd(name, sd_image+num);
|
||||
ret = x2trd(name, sd_image+ index);
|
||||
}
|
||||
else
|
||||
{
|
||||
writable = FileCanWrite(name);
|
||||
ret = FileOpenEx(&sd_image[num], name, writable ? (O_RDWR | O_SYNC) : O_RDONLY);
|
||||
ret = FileOpenEx(&sd_image[index], name, writable ? (O_RDWR | O_SYNC) : O_RDONLY);
|
||||
}
|
||||
|
||||
if (!ret)
|
||||
{
|
||||
writable = 0;
|
||||
sd_image[num].size = 0;
|
||||
sd_image[index].size = 0;
|
||||
printf("Failed to open file %s\n", name);
|
||||
printf("Eject image from %d slot\n", num);
|
||||
printf("Eject image from %d slot\n", index);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Mount %s as %s on %d slot\n", name, writable ? "read-write" : "read-only", num);
|
||||
printf("Mount %s as %s on %d slot\n", name, writable ? "read-write" : "read-only", index);
|
||||
}
|
||||
|
||||
user_io_sd_set_config();
|
||||
@@ -847,27 +847,27 @@ int user_io_file_mount(int num, char *name)
|
||||
spi8(UIO_SET_SDINFO);
|
||||
if (io_ver)
|
||||
{
|
||||
spi_w((uint16_t)(sd_image[num].size));
|
||||
spi_w((uint16_t)(sd_image[num].size>>16));
|
||||
spi_w((uint16_t)(sd_image[num].size>>32));
|
||||
spi_w((uint16_t)(sd_image[num].size>>48));
|
||||
spi_w((uint16_t)(sd_image[index].size));
|
||||
spi_w((uint16_t)(sd_image[index].size>>16));
|
||||
spi_w((uint16_t)(sd_image[index].size>>32));
|
||||
spi_w((uint16_t)(sd_image[index].size>>48));
|
||||
}
|
||||
else
|
||||
{
|
||||
spi32le(sd_image[num].size);
|
||||
spi32le(sd_image[num].size>>32);
|
||||
spi32le(sd_image[index].size);
|
||||
spi32le(sd_image[index].size>>32);
|
||||
}
|
||||
DisableIO();
|
||||
|
||||
// notify core of possible sd image change
|
||||
spi_uio_cmd8(UIO_SET_SDSTAT, (1<<num) | (writable ? 0 : 0x80));
|
||||
spi_uio_cmd8(UIO_SET_SDSTAT, (1<< index) | (writable ? 0 : 0x80));
|
||||
return ret ? 1 : 0;
|
||||
}
|
||||
|
||||
int user_io_file_tx(char* name, unsigned char index)
|
||||
int user_io_file_tx(char* name, unsigned char index, char opensave)
|
||||
{
|
||||
fileTYPE f = { 0 };
|
||||
static uint8_t buf[512];
|
||||
static uint8_t buf[1024];
|
||||
|
||||
if (!FileOpen(&f, name)) return 0;
|
||||
|
||||
@@ -923,6 +923,13 @@ int user_io_file_tx(char* name, unsigned char index)
|
||||
|
||||
FileClose(&f);
|
||||
|
||||
if (opensave)
|
||||
{
|
||||
strcpy((char*)buf, name);
|
||||
strcpy((char*)buf + strlen(name) - 4, ".sav");
|
||||
user_io_file_mount((char*)buf);
|
||||
}
|
||||
|
||||
// signal end of transmission
|
||||
EnableFpga();
|
||||
spi8(UIO_FILE_TX);
|
||||
@@ -1272,7 +1279,7 @@ void user_io_poll()
|
||||
// ... and write it to disk
|
||||
int done = 0;
|
||||
|
||||
if (sd_image[disk].size)
|
||||
if ((sd_image[disk].size>>9)>lba)
|
||||
{
|
||||
diskled_on();
|
||||
if (FileSeekLBA(&sd_image[disk], lba))
|
||||
|
||||
@@ -183,10 +183,10 @@ 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 *, unsigned char);
|
||||
int user_io_file_tx(char* name, unsigned char index = 0, char opensave = 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);
|
||||
int user_io_file_mount(int num, char *name);
|
||||
char *user_io_get_core_name();
|
||||
const char *user_io_get_core_name_ex();
|
||||
char is_menu_core();
|
||||
|
||||
Reference in New Issue
Block a user