From ca37f771036c862076cac9f7ca3145b15b8ecb9e Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 2 Nov 2022 01:20:50 +0200 Subject: [PATCH] cdrom: handle fifo overreads based on nocash doc notaz/pcsx_rearmed#269 --- libpcsxcore/cdrom.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 12945d60..e1065739 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -1430,7 +1430,7 @@ void cdrWrite1(unsigned char rt) { } unsigned char cdrRead2(void) { - unsigned char ret = 0; + unsigned char ret = cdr.Transfer[0x920]; if (cdr.FifoOffset < cdr.FifoSize) ret = cdr.Transfer[cdr.FifoOffset++]; @@ -1562,10 +1562,12 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) { { memcpy(ptr, cdr.Transfer + cdr.FifoOffset, size); cdr.FifoOffset += size; - psxCpu->Clear(madr, size / 4); } - if (size < cdsize) + if (size < cdsize) { CDR_LOG_I("cdrom: dma3 %d/%d\n", size, cdsize); + memset(ptr + size, cdr.Transfer[0x920], cdsize - size); + } + psxCpu->Clear(madr, cdsize / 4); CDRDMA_INT((cdsize/4) * 24); @@ -1655,7 +1657,7 @@ int cdrFreeze(void *f, int Mode) { if (Mode == 0) { getCdInfo(); - cdr.FifoOffset = tmp; + cdr.FifoOffset = tmp < DATA_SIZE ? tmp : DATA_SIZE; cdr.FifoSize = (cdr.Mode & 0x20) ? 2340 : 2048 + 12; // read right sub data -- 2.39.5