gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Audio > GBA Sound Interrupt Mode doubt : (

#3904 - rome - Wed Mar 12, 2003 3:28 pm

My GBA Interrrput Engine works perfectly, but when i try use it with graphics, the screen stay blank....
when i comment line "REG_IME = 1"
the sound does not work, but graphics back to work...
waht happening???
my code:

Code:


REG_INTERUPT = (u32)&InterruptProcess;


//******************************************************
void InterruptProcess(void)
{
   Game.pr_SoundDevice->HandleSound();
}
//******************************************************

//******************************************************
void WGBASoundDevice::Initialize()
{

... (init other things)


   REG_SGCNT0_H = *(u16*) &snd_ctrl;
    REG_SGCNT1   = SND_ENABLED;  //turn sound chip on

   // Clear the FIFO
   REG_SGFIF0A = 0;
   
   // Enable IRQ for timer 0
   REG_IE |= 0x8;   

    //enable interrupts (comment it and graphics will be showed!!!!)
    REG_IME=1;

    //enable timer at CPU freq/1024 +irq =16384Khz sample rate
    REG_TM0D   =0xffff;
    REG_TM0CNT =0x00C3;

    return;
}

#3905 - DekuTree64 - Wed Mar 12, 2003 4:49 pm

So HandleSound just writes one sample to the FIFO, right? That's very slow. If you just want to play a single sound, set SOUNDA_FIFORESET (bit11) in SGCNT0_H, and use DMA1 with dest FIFOA, src is your sample, and then set the mode to 0xb640. Count is ignored in sound mode (bits 12 and 13 set (included in 0xb640)), so set it to 0. But before that, set TM0D to 65536 - ((1 << 24) / sndFreq) (1 << 24 is the CPU frequency). Actually for 16384 hz, setting it to 0xffff with the divide by 1024 bit set like you have it will work ust the same. Also, you'll need another timer to count samples played so you don't keep playing data past the end of your sample. The easiest way to do it is set TM1D to 65536 - sampleCount, and set the cascade and IRQ bits in TM1CNT. Then make a little IRQ function that turns the DMA of when TM1 overflows.

#3908 - rome - Wed Mar 12, 2003 5:12 pm

you are completely right! i know : )

but my problem continues yet...

i dont know why my game just not render when enable the Interrupt Enable Register (REG_IE) and set 0x8 to Interrrupt Flags Register (REG_IF)

#3909 - DekuTree64 - Wed Mar 12, 2003 5:55 pm

Hmm, yea, I guess it would still have plenty of time to render.
Ah, I think I found it. REG_INTERUPT = (u32)&InterruptProcess; shouldn't have that & in there. The name of the function is its address, so I don't know what the address of its adress would be, and I doubt the compiler does either^^ Probably just returns a 0 or something, so when your interrupt is triggered, it goes into nowhere and never comes back.