From eb1455cebbcabdf8814c9685e4978fad48a57777 Mon Sep 17 00:00:00 2001 From: Sorgelig Date: Sun, 13 Feb 2022 23:16:30 +0800 Subject: [PATCH] PSX: don't create memory card till first save. --- support/psx/psx.cpp | 44 +++++++++++++++++++------------------------- support/psx/psx.h | 1 + user_io.cpp | 7 ++++++- user_io.h | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/support/psx/psx.cpp b/support/psx/psx.cpp index 546c423..e8527a1 100644 --- a/support/psx/psx.cpp +++ b/support/psx/psx.cpp @@ -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) diff --git a/support/psx/psx.h b/support/psx/psx.h index 5bcc725..fd1ce5e 100644 --- a/support/psx/psx.h +++ b/support/psx/psx.h @@ -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 diff --git a/user_io.cpp b/user_io.cpp index 5f281a4..c5936c4 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -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])); diff --git a/user_io.h b/user_io.h index fdfb51c..84c5c24 100644 --- a/user_io.h +++ b/user_io.h @@ -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);