cdrom: merge shalma's suggestions
authornotaz <notasas@gmail.com>
Thu, 30 Jun 2011 23:33:20 +0000 (02:33 +0300)
committernotaz <notasas@gmail.com>
Tue, 12 Jul 2011 21:28:48 +0000 (00:28 +0300)
http://www.gp32x.com/board/index.php?/topic/57973-pcsx-rearmed/page__view__findpost__p__952591

libpcsxcore/cdrom.c

index 1569839..cc377b9 100644 (file)
@@ -1937,6 +1937,7 @@ void cdrWrite3(unsigned char rt) {
 
 void psxDma3(u32 madr, u32 bcr, u32 chcr) {
        u32 cdsize;
+       int size;
        u8 *ptr;
 
 #ifdef CDR_LOG
@@ -1981,15 +1982,12 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) {
                        - CdlPlay
                        - Spams DMA3 and gets buffer overrun
                        */
-
-                       if( (cdr.pTransfer-cdr.Transfer) + cdsize > 2352 )
-                       {
-                               // avoid crash - probably should wrap here
-                               //memcpy(ptr, cdr.pTransfer, cdsize);
-                       }
-                       else
+                       size = CD_FRAMESIZE_RAW - (cdr.pTransfer - cdr.Transfer);
+                       if (size > cdsize)
+                               size = cdsize;
+                       if (size > 0)
                        {
-                               memcpy(ptr, cdr.pTransfer, cdsize);
+                               memcpy(ptr, cdr.pTransfer, size);
                        }
 
                        psxCpu->Clear(madr, cdsize / 4);