I was originally trying to use DMA with Wolf32X for the sound. This was the code:
Code: Select all
// init the sound hardware
MARS_PWM_CTRL = 0x0185; // TM = 1, RTP, RMD = right, LMD = left
if (MARS_VDP_DISPMODE & MARS_PAL_FORMAT)
MARS_PWM_CYCLE = 521; //44.1kHz
else
MARS_PWM_CYCLE = 516; //44.1kHz
while (1)
{
// only do sound when sound subsytem initialized
while (MARS_SYS_COMM4 == 1)
{
// start DMA on first buffer and fill second
SH2_DMA_SAR1 = (unsigned long)sndbuf & 0x1FFFFFFF;
SH2_DMA_DAR1 = (unsigned long)&MARS_PWM_LEFT & 0x1FFFFFFF; // storing a long here will set left and right
SH2_DMA_TCR1 = (unsigned long)NUM_SAMPS; // number longs
SH2_DMA_CHCR1 = (unsigned long)0x18E1; // dest fixed, src incr, size long, ext req, dack mem to dev, dack hi, dack edge, dreq rising edge, cycle-steal, dual addr, intr disabled, clear TE, dma enabled
SH2_DMA_DMAOR = (unsigned long)1; // enable DMA - starts dma
FillSoundBuff(NUM_SAMPS * 2 * 2);
// wait on DMA
while (!(SH2_DMA_CHCR1 & 2)) ; // wait on TE
SH2_DMA_DMAOR = (unsigned long)0; // disable DMA
SH2_DMA_CHCR1 = (unsigned long)0x18E0; // clear TE, dma disabled
// start DMA on second buffer and fill first
SH2_DMA_SAR1 = ((unsigned long)sndbuf & 0x1FFFFFFF) + NUM_SAMPS * 2 * 2;
SH2_DMA_DAR1 = (unsigned long)&MARS_PWM_LEFT & 0x1FFFFFFF; // storing a long here will set left and right
SH2_DMA_TCR1 = (unsigned long)NUM_SAMPS; // number longs
SH2_DMA_CHCR1 = (unsigned long)0x18E1; // dest fixed, src incr, size long, ext req, dack mem to dev, dack hi, dack edge, dreq rising edge, cycle-steal, dual addr, intr disabled, clear TE, dma enabled
SH2_DMA_DMAOR = (unsigned long)1; // enable DMA - starts dma
FillSoundBuff(0);
// wait on DMA
while (!(SH2_DMA_CHCR1 & 2)) ; // wait on TE
SH2_DMA_DMAOR = (unsigned long)0; // disable DMA
SH2_DMA_CHCR1 = (unsigned long)0x18E0; // clear TE, dma disabled
}
}
It plays stereo samples via the slave SH2 DMA... well, it was supposed to. It didn't work right, but it did at least make noise on real hardware. I didn't try to debug it because none of the emulators at the time supported DMA PWM audio, so I just switched to SH2 driven audio out using the slave.
I've thought about going back and trying to get the DMA PWM to work as that would be a lot less overhead for the audio. By the way, how are you testing your code? If you're using an emulator, it may not support DMA PWM as I've never seen a 32X game that used it. Gens/GS only just added DMA PWM a few days ago. I'm not sure if KEGA supports it or not.