From 9d7f739e34cfaa284f8bdd1f36bf6e8d7b9d9cef Mon Sep 17 00:00:00 2001 From: Zakk Date: Tue, 12 Mar 2024 19:53:45 -0400 Subject: [PATCH] PSX: match user_io buffer size to chd hunk size --- support/psx/psx.cpp | 9 +++++++++ support/psx/psx.h | 1 + user_io.cpp | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/support/psx/psx.cpp b/support/psx/psx.cpp index baefd9e..34cbf36 100644 --- a/support/psx/psx.cpp +++ b/support/psx/psx.cpp @@ -467,6 +467,15 @@ void psx_fill_blanksave(uint8_t *buffer, uint32_t lba, int cnt) static toc_t toc = {}; #define CD_SECTOR_LEN 2352 +int psx_chd_hunksize() +{ + if (toc.chd_f) + return toc.chd_hunksize; + + return 0; +} + + void psx_read_cd(uint8_t *buffer, int lba, int cnt) { //printf("req lba=%d, cnt=%d\n", lba, cnt); diff --git a/support/psx/psx.h b/support/psx/psx.h index 749d325..2ea5445 100644 --- a/support/psx/psx.h +++ b/support/psx/psx.h @@ -4,6 +4,7 @@ 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); void psx_read_cd(uint8_t *buffer, int lba, int cnt); +int psx_chd_hunksize(); const char* psx_get_game_id(); void psx_poll(); diff --git a/user_io.cpp b/user_io.cpp index 4c7d20c..3cca5d6 100644 --- a/user_io.cpp +++ b/user_io.cpp @@ -3118,6 +3118,13 @@ void user_io_poll() else if (op & 1) { uint32_t buf_n = sizeof(buffer[0]) / blksz; + int psx_blksz = 0; + if (is_psx() && blksz == 2352) + { + //returns 0 if the mounted disk is not a chd, otherwise returns the chd hunksize in bytes + psx_blksz = psx_chd_hunksize(); + if (psx_blksz && psx_blksz <= sizeof(buffer[0])) buf_n = psx_blksz / blksz; + } //printf("SD RD (%llu,%d) on %d, WIDE=%d\n", lba, blksz, disk, fio_size); int done = 0;