void coopTimerStart(int timer, ClockDivider divider, u16 ticks, VoidFn callback) { timer &= 3; TIMER_DATA(timer) = ticks; if (callback) { coopIrqSet(IRQ_TIMER(timer), callback); irqEnable(IRQ_TIMER(timer)); TIMER_CR(timer) = TIMER_IRQ_REQ | divider | TIMER_ENABLE; }else TIMER_CR(timer) = divider | TIMER_ENABLE; }
//--------------------------------------------------------------------------------- void timerStart(int timer, ClockDivider divider, u16 ticks, VoidFn callback){ //--------------------------------------------------------------------------------- sassert(timer < 4, "timer must be in range 0 - 3"); TIMER_DATA(timer) = ticks; if(callback) { irqSet(IRQ_TIMER(timer), callback); irqEnable(IRQ_TIMER(timer)); TIMER_CR(timer) = TIMER_IRQ_REQ | divider | TIMER_ENABLE; } else { TIMER_CR(timer) = divider | TIMER_ENABLE; } }
// Play one 48th of a measure of music static void stage_step() { REG_IME = 0; int halt = 0; switch(REG_IF) { case IRQ_TIMER(0) : if(!--wait) { if(sound_data[index].CH1_FRQ) { REG_SND1SWP = sound_data[index].CH1_SWP; REG_SND1ENV = sound_data[index].CH1_ENV; REG_SND1FRQ = sound_data[index].CH1_FRQ; } if(sound_data[index].CH2_FRQ) { REG_SND2ENV = sound_data[index].CH2_ENV; REG_SND2FRQ = sound_data[index].CH2_FRQ; } if(sound_data[index].CH4_FRQ) { REG_SND4ENV = sound_data[index].CH4_ENV; REG_SND4FRQ = sound_data[index].CH4_FRQ; } wait = sound_data[index].LEN; if(++index == 257) { if(1) { index = 0; } else { halt = 1; } } } break; default: break; } REG_IF = REG_IF; if(!halt) { REG_IME = IRQ_ENABLE; } }
// Begin playing the music void stage_play() { REG_IME = 0; REG_ISR_MAIN = stage_step; REG_IE = IRQ_TIMER(0); REG_TMD(0) = BPM_QUAN_TRANSFORM; REG_TMCNT(0) = TM_ENABLE | TM_IRQ | TM_FREQ_1024; REG_SNDSTAT = MASTER_SND_EN; REG_SNDDMGCNT = CHAN_EN_L(1) | CHAN_EN_R(1) | CHAN_EN_L(2) | CHAN_EN_R(2) | CHAN_EN_L(4) | CHAN_EN_R(4) | LEFT_VOL(7) | RIGHT_VOL(7); index = 0; wait = 1; REG_IME = IRQ_ENABLE; }