PSX: don't create memory card till first save.

This commit is contained in:
Sorgelig
2022-02-13 23:16:30 +08:00
parent 7d896cd85a
commit eb1455cebb
4 changed files with 27 additions and 27 deletions

View File

@@ -167,38 +167,32 @@ static uint16_t libCryptMask(const char *sbifile)
static void psx_mount_save(const char *filename)
{
user_io_set_index(2);
user_io_set_download(1);
int mounted = 0;
if (strlen(filename))
{
FileGenerateSavePath(filename, buf, 0);
if(!FileExists(buf))
{
uint8_t *mcd = new uint8_t[MCD_SIZE];
if (mcd)
{
memset(mcd, 0, MCD_SIZE);
memcpy(mcd, mcdheader, sizeof(mcdheader));
FileSave(buf, mcd, MCD_SIZE);
delete(mcd);
}
}
if (FileExists(buf))
{
user_io_file_mount(buf, 2);
StoreIdx_S(2, buf);
mounted = 1;
}
user_io_file_mount(buf, 2, 1, MCD_SIZE);
StoreIdx_S(2, buf);
}
if (!mounted)
else
{
user_io_file_mount("", 2);
StoreIdx_S(2, "");
}
user_io_set_download(0);
}
void psx_fill_blanksave(uint8_t *buffer, uint32_t lba, int cnt)
{
uint32_t offset = lba * 1024;
uint32_t size = cnt * 1024;
if ((offset + size) <= sizeof(mcdheader))
{
memcpy(buffer, mcdheader + offset, size);
}
else
{
memset(buffer, 0, size);
}
}
void psx_mount_cd(int f_index, int s_index, const char *filename)
@@ -252,7 +246,7 @@ void psx_mount_cd(int f_index, int s_index, const char *filename)
if (!loaded) Info("CD BIOS not found!", 4000);
}
if(*last_dir) psx_mount_save(last_dir);
psx_mount_save(last_dir);
}
if (loaded)

View File

@@ -2,5 +2,6 @@
#define PSX_H
void psx_mount_cd(int f_index, int s_index, const char *filename);
void psx_fill_blanksave(uint8_t *buffer, uint32_t lba, int cnt);
#endif

View File

@@ -1674,7 +1674,7 @@ void user_io_file_info(const char *ext)
DisableFpga();
}
int user_io_file_mount(const char *name, unsigned char index, char pre)
int user_io_file_mount(const char *name, unsigned char index, char pre, int pre_size)
{
int writable = 0;
int ret = 0;
@@ -1764,6 +1764,7 @@ int user_io_file_mount(const char *name, unsigned char index, char pre)
{
sd_image[index].type = 2;
strcpy(sd_image[index].path, name);
size = pre_size;
}
if (io_ver)
@@ -2820,6 +2821,10 @@ void user_io_poll()
memcpy(buffer[disk], "HUBM\x00\x88\x10\x80", 8);
}
}
else if (is_psx())
{
psx_fill_blanksave(buffer[disk], lba, blks);
}
else
{
memset(buffer[disk], -1, sizeof(buffer[disk]));

View File

@@ -197,7 +197,7 @@ uint32_t user_io_8bit_set_status(uint32_t, uint32_t, int ex = 0);
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);
int user_io_file_mount(const char *name, unsigned char index = 0, char pre = 0, int pre_size = 0);
char *user_io_make_filepath(const char *path, const char *filename);
char *user_io_get_core_name(int orig = 0);
char *user_io_get_core_path(const char *suffix = NULL, int recheck = 0);