2009-02-06 19:52:59 +00:00
|
|
|
/* ZeroSPU2
|
2010-01-16 16:08:17 +00:00
|
|
|
* Copyright (C) 2006-2010 zerofrog
|
2009-02-06 19:52:59 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "zerospu2.h"
|
2010-02-12 11:42:29 +00:00
|
|
|
#include "zerodma.h"
|
2009-02-06 19:52:59 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "SoundTouch/SoundTouch.h"
|
|
|
|
#include "SoundTouch/WavFile.h"
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
void CALLBACK SPU2readDMAMem(u16 *pMem, int size, int channel)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
u32 spuaddr = C_SPUADDR(channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
SPU2_LOG("SPU2 readDMAMem(%d) size %x, addr: %x\n", channel, size, pMem);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
for (u32 i = 0; i < size; i++)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
|
|
|
*pMem++ = *(u16*)(spu2mem + spuaddr);
|
2010-02-12 11:42:29 +00:00
|
|
|
if (spu2attr(channel).irq && (C_IRQA(channel) == spuaddr))
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(spuaddr, channel);
|
|
|
|
IRQINFO |= (4 * (channel + 1));
|
|
|
|
SPU2_LOG("SPU2readDMAMem(%d):interrupt\n", channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
irqCallbackSPU2();
|
|
|
|
}
|
|
|
|
|
|
|
|
spuaddr++; // inc spu addr
|
|
|
|
if (spuaddr > 0x0fffff) spuaddr=0; // wrap at 2Mb
|
|
|
|
}
|
|
|
|
|
|
|
|
spuaddr += 19; //Transfer Local To Host TSAH/L + Data Size + 20 (already +1'd)
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(spuaddr, channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
|
|
|
// DMA complete
|
2010-02-12 11:42:29 +00:00
|
|
|
spu2stat_clear_80(channel);
|
|
|
|
SPUStartCycle[channel] = SPUCycles;
|
|
|
|
SPUTargetCycle[channel] = size;
|
|
|
|
interrupt |= (1 << (1 + channel));
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK SPU2readDMA4Mem(u16 *pMem, int size)
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2readDMA4Mem()\n");
|
|
|
|
return SPU2readDMAMem(pMem, size, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK SPU2readDMA7Mem(u16* pMem, int size)
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2readDMA7Mem()\n");
|
|
|
|
return SPU2readDMAMem(pMem, size, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// WRITE
|
|
|
|
|
|
|
|
// AutoDMA's are used to transfer to the DIRECT INPUT area of the spu2 memory
|
|
|
|
// Left and Right channels are always interleaved together in the transfer so
|
|
|
|
// the AutoDMA's deinterleaves them and transfers them. An interrupt is
|
|
|
|
// generated when half of the buffer (256 short-words for left and 256
|
|
|
|
// short-words for right ) has been transferred. Another interrupt occurs at
|
|
|
|
// the end of the transfer.
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
int ADMASWrite(int channel)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
|
|
|
u32 spuaddr;
|
2010-02-12 11:42:29 +00:00
|
|
|
ADMA *Adma = &adma[channel];
|
2009-02-06 19:52:59 +00:00
|
|
|
|
|
|
|
if (interrupt & 0x2)
|
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
WARN_LOG("ADMASWrite(%d) returning for interrupt\n", channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-02-12 11:42:29 +00:00
|
|
|
|
2009-02-06 19:52:59 +00:00
|
|
|
if (Adma->AmountLeft <= 0)
|
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
WARN_LOG("ADMASWrite(%d) amount left is 0\n", channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert( Adma->AmountLeft >= 512 );
|
2010-02-12 11:42:29 +00:00
|
|
|
spuaddr = C_SPUADDR(channel);
|
|
|
|
u32 left_addr = spuaddr + 0x2000 + c_offset(channel);
|
|
|
|
u32 right_addr = left_addr + 0x200;
|
2009-02-06 19:52:59 +00:00
|
|
|
|
|
|
|
// SPU2 Deinterleaves the Left and Right Channels
|
2010-02-12 11:42:29 +00:00
|
|
|
memcpy((s16*)(spu2mem + left_addr),(s16*)Adma->MemAddr,512);
|
2009-02-06 19:52:59 +00:00
|
|
|
Adma->MemAddr += 256;
|
2010-02-12 11:42:29 +00:00
|
|
|
memcpy((s16*)(spu2mem + right_addr),(s16*)Adma->MemAddr,512);
|
2009-02-06 19:52:59 +00:00
|
|
|
Adma->MemAddr += 256;
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
if (spu2attr(channel).irq && (irq_test1(channel, spuaddr) || irq_test2(channel, spuaddr)))
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
IRQINFO |= (4 * (channel + 1));
|
|
|
|
WARN_LOG("ADMAMem access(%d): interrupt\n", channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
irqCallbackSPU2();
|
|
|
|
}
|
|
|
|
|
|
|
|
spuaddr = (spuaddr + 256) & 511;
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(spuaddr, channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
|
|
|
Adma->AmountLeft -= 512;
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
return (Adma->AmountLeft <= 0);
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
void SPU2writeDMAMem(u16* pMem, int size, int channel)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
|
|
|
u32 spuaddr;
|
2010-02-12 11:42:29 +00:00
|
|
|
ADMA *Adma = &adma[channel];
|
|
|
|
s32 offset = (channel == 0) ? 0 : 0x400;
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
SPU2_LOG("SPU2 writeDMAMem size %x, addr: %x(spu2:%x)"/*, ctrl: %x, adma: %x\n"*/, \
|
|
|
|
size, pMem, C_SPUADDR(channel)/*, spu2Ru16(REG_C0_CTRL + offset), spu2Ru16(REG_C0_ADMAS + offset)*/);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
if (spu2admas(channel) && (spu2attr(channel).dma == 0) && size)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
|
|
|
if (!Adma->Enabled ) Adma->Index = 0;
|
|
|
|
|
|
|
|
Adma->MemAddr = pMem;
|
|
|
|
Adma->AmountLeft = size;
|
2010-02-12 11:42:29 +00:00
|
|
|
SPUTargetCycle[channel] = size;
|
|
|
|
spu2stat_clear_80(channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
if (!Adma->Enabled || (Adma->Index > 384))
|
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(0, channel);
|
|
|
|
if (ADMASWrite(channel))
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
SPUStartCycle[channel] = SPUCycles;
|
|
|
|
interrupt |= (1 << (1 + channel));
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Adma->Enabled = 1;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-20 03:22:19 +00:00
|
|
|
#ifdef ZEROSPU2_DEVBUILD
|
2010-02-12 11:42:29 +00:00
|
|
|
if ((conf.Log && conf.options & OPTION_RECORDING) && (channel == 1))
|
2009-02-06 19:52:59 +00:00
|
|
|
LogPacketSound(pMem, 0x8000);
|
|
|
|
#endif
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
spuaddr = C_SPUADDR(channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
memcpy((u8*)(spu2mem + spuaddr),(u8*)pMem,size << 1);
|
|
|
|
spuaddr += size;
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(spuaddr, channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
if (spu2attr(channel).irq && (spuaddr < C_IRQA(channel) && (C_IRQA(channel) <= (spuaddr + 0x20))))
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
IRQINFO |= 4 * (channel + 1);
|
|
|
|
SPU2_LOG("SPU2writeDMAMem:interrupt\n");
|
2009-02-06 19:52:59 +00:00
|
|
|
irqCallbackSPU2();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spuaddr > 0xFFFFE) spuaddr = 0x2800;
|
2010-02-12 11:42:29 +00:00
|
|
|
C_SPUADDR_SET(spuaddr, channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
MemAddr[channel] += size << 1;
|
|
|
|
spu2stat_clear_80(channel);
|
|
|
|
SPUStartCycle[channel] = SPUCycles;
|
|
|
|
SPUTargetCycle[channel] = size;
|
|
|
|
interrupt |= (1 << (channel + 1));
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 11:42:29 +00:00
|
|
|
void CALLBACK SPU2interruptDMA(int channel)
|
2009-02-06 19:52:59 +00:00
|
|
|
{
|
2010-02-12 11:42:29 +00:00
|
|
|
SPU2_LOG("SPU2 interruptDMA(%d)\n", channel);
|
|
|
|
spu2attr(channel).dma = 0;
|
|
|
|
spu2stat_set_80(channel);
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 12:36:49 +00:00
|
|
|
#ifndef ENABLE_NEW_IOPDMA_SPU2
|
|
|
|
void CALLBACK SPU2writeDMA4Mem(u16* pMem, int size)
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2writeDMA4Mem()\n");
|
|
|
|
SPU2writeDMAMem(pMem, size, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK SPU2writeDMA7Mem(u16* pMem, int size)
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2writeDMA7Mem()\n");
|
|
|
|
SPU2writeDMAMem(pMem, size, 1);
|
|
|
|
}
|
|
|
|
|
2009-02-06 19:52:59 +00:00
|
|
|
void CALLBACK SPU2interruptDMA4()
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2interruptDMA4()\n");
|
2010-02-07 12:36:49 +00:00
|
|
|
SPU2interruptDMA(4);
|
2009-02-06 19:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK SPU2interruptDMA7()
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2interruptDMA7()\n");
|
2010-02-07 12:36:49 +00:00
|
|
|
SPU2interruptDMA(7);
|
2010-01-16 16:08:17 +00:00
|
|
|
}
|
2010-02-07 12:36:49 +00:00
|
|
|
#else
|
|
|
|
s32 CALLBACK SPU2dmaRead(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
|
|
|
|
{
|
|
|
|
// Needs implementation.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 CALLBACK SPU2dmaWrite(s32 channel, u32* data, u32 bytesLeft, u32* bytesProcessed)
|
|
|
|
{
|
|
|
|
// Needs implementation.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CALLBACK SPU2dmaInterrupt(s32 channel)
|
|
|
|
{
|
|
|
|
LOG_CALLBACK("SPU2dmaInterruptDMA()\n");
|
|
|
|
SPU2interruptDMA(channel);
|
|
|
|
}
|
|
|
|
#endif
|