cspace: add forgotten length decrement
[pcsx_rearmed.git] / libpcsxcore / psxdma.c
index b0f3fba..d3b8572 100644 (file)
@@ -122,7 +122,8 @@ static u32 gpuDmaChainSize(u32 addr) {
                // next 32-bit pointer
                addr = psxMu32( addr & ~0x3 ) & 0xffffff;
                size += 1;
-       } while (addr != 0xffffff);
+       } while (!(addr & 0x800000)); // contrary to some documentation, the end-of-linked-list marker is not actually 0xFF'FFFF
+                                  // any pointer with bit 23 set will do.
 
        return size;
 }
@@ -184,7 +185,7 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU
                        size = GPU_dmaChain((u32 *)psxM, madr & 0x1fffff);
                        if ((int)size <= 0)
                                size = gpuDmaChainSize(madr);
-                       HW_GPU_STATUS &= ~PSXGPU_nBUSY;
+                       HW_GPU_STATUS &= SWAP32(~PSXGPU_nBUSY);
 
                        // we don't emulate progress, just busy flag and end irq,
                        // so pretend we're already at the last block
@@ -216,11 +217,11 @@ void gpuInterrupt() {
                HW_DMA2_CHCR &= SWAP32(~0x01000000);
                DMA_INTERRUPT(2);
        }
-       HW_GPU_STATUS |= PSXGPU_nBUSY; // GPU no longer busy
+       HW_GPU_STATUS |= SWAP32(PSXGPU_nBUSY); // GPU no longer busy
 }
 
 void psxDma6(u32 madr, u32 bcr, u32 chcr) {
-       u32 size;
+       u32 words;
        u32 *mem = (u32 *)PSXM(madr);
 
 #ifdef PSXDMA_LOG
@@ -238,15 +239,18 @@ void psxDma6(u32 madr, u32 bcr, u32 chcr) {
                }
 
                // already 32-bit size
-               size = bcr;
+               words = bcr;
 
                while (bcr--) {
                        *mem-- = SWAP32((madr - 4) & 0xffffff);
                        madr -= 4;
                }
-               mem++; *mem = 0xffffff;
+               *++mem = SWAP32(0xffffff);
 
-               GPUOTCDMA_INT(size);
+               //GPUOTCDMA_INT(size);
+               // halted
+               psxRegs.cycle += words;
+               GPUOTCDMA_INT(16);
                return;
        }
 #ifdef PSXDMA_LOG