From: notaz Date: Tue, 1 Nov 2022 23:20:50 +0000 (+0200) Subject: cdrom: handle fifo overreads X-Git-Tag: r24l~350 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca37f771036c862076cac9f7ca3145b15b8ecb9e;p=pcsx_rearmed.git cdrom: handle fifo overreads based on nocash doc notaz/pcsx_rearmed#269 --- 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