public static int OPMInit(int num, int clock, int rate,FM_TIMERHANDLER TimerHandler, FM_IRQHANDLER IRQHandler) { if (FMOPM!=null) return (-1); /* duplicate init. */ cur_chip = null; /* hiro-shi!! */ YM2151NumChips = num; /* allocate ym2151 state space */ FMOPM = new YM2151[YM2151NumChips]; for (int i = 0; i < YM2151NumChips; i++) FMOPM[i] = new YM2151(); /* allocate total lebel table (128kb space) */ if (FMInitTable()==0) { FMOPM = null; return (-1); } for (int i = 0; i < YM2151NumChips; i++) { FMOPM[i].ST.index = (byte)i; FMOPM[i].ST.clock = clock; FMOPM[i].ST.rate = rate; /* FMOPM[i].ST.irq = 0; */ /* FMOPM[i].ST.status = 0; */ FMOPM[i].ST.timermodel = FM_TIMER_INTERVAL; FMOPM[i].ST.freqbase = rate !=0? ((double)clock / rate) / 64 : 0; FMOPM[i].ST.TimerBase = 1.0 / ((double)clock / 64.0); /* Extend handler */ FMOPM[i].ST.Timer_Handler = TimerHandler; FMOPM[i].ST.IRQ_Handler = IRQHandler; /* Reset callback handler of CT0/1 */ FMOPM[i].PortWrite = null; OPMResetChip(i); } return (0); }
static void OPM_CALC_FCOUNT(YM2151 OPM, FM_CH CH) { if (CH.SLOT[SLOT1].Incr == unchecked((uint)-1)) { int fc = (int)CH.fc; int kc = CH.kcode; CALC_FCSLOT(CH.SLOT[SLOT1], (int)(OPM.KC_TABLE[fc + CH.SLOT[SLOT1].DT2]), kc); CALC_FCSLOT(CH.SLOT[SLOT2], (int)(OPM.KC_TABLE[fc + CH.SLOT[SLOT2].DT2]), kc); CALC_FCSLOT(CH.SLOT[SLOT3], (int)(OPM.KC_TABLE[fc + CH.SLOT[SLOT3].DT2]), kc); CALC_FCSLOT(CH.SLOT[SLOT4], (int)(OPM.KC_TABLE[fc + CH.SLOT[SLOT4].DT2]), kc); } }