Lines Matching refs:OPL

249 static inline void OPL_STATUS_SET(FM_OPL *OPL,int flag)  in OPL_STATUS_SET()  argument
252 OPL->status |= flag; in OPL_STATUS_SET()
253 if(!(OPL->status & 0x80)) in OPL_STATUS_SET()
255 if(OPL->status & OPL->statusmask) in OPL_STATUS_SET()
257 OPL->status |= 0x80; in OPL_STATUS_SET()
263 static inline void OPL_STATUS_RESET(FM_OPL *OPL,int flag) in OPL_STATUS_RESET() argument
266 OPL->status &=~flag; in OPL_STATUS_RESET()
267 if((OPL->status & 0x80)) in OPL_STATUS_RESET()
269 if (!(OPL->status & OPL->statusmask) ) in OPL_STATUS_RESET()
271 OPL->status &= 0x7f; in OPL_STATUS_RESET()
277 static inline void OPL_STATUSMASK_SET(FM_OPL *OPL,int flag) in OPL_STATUSMASK_SET() argument
279 OPL->statusmask = flag; in OPL_STATUSMASK_SET()
281 OPL_STATUS_SET(OPL,0); in OPL_STATUSMASK_SET()
282 OPL_STATUS_RESET(OPL,0); in OPL_STATUSMASK_SET()
379 static inline void set_mul(FM_OPL *OPL,int slot,int v) in set_mul() argument
381 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_mul()
393 static inline void set_ksl_tl(FM_OPL *OPL,int slot,int v) in set_ksl_tl() argument
395 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_ksl_tl()
402 if( !(OPL->mode&0x80) ) in set_ksl_tl()
409 static inline void set_ar_dr(FM_OPL *OPL,int slot,int v) in set_ar_dr() argument
411 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_ar_dr()
416 SLOT->AR = ar ? &OPL->AR_TABLE[ar<<2] : RATE_0; in set_ar_dr()
420 SLOT->DR = dr ? &OPL->DR_TABLE[dr<<2] : RATE_0; in set_ar_dr()
426 static inline void set_sl_rr(FM_OPL *OPL,int slot,int v) in set_sl_rr() argument
428 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_sl_rr()
435 SLOT->RR = &OPL->DR_TABLE[rr<<2]; in set_sl_rr()
572 static void init_timetables( FM_OPL *OPL , int ARRATE , int DRRATE ) in init_timetables() argument
578 for (i = 0;i < 4;i++) OPL->AR_TABLE[i] = OPL->DR_TABLE[i] = 0; in init_timetables()
580 rate = OPL->freqbase; /* frequency rate */ in init_timetables()
584 OPL->AR_TABLE[i] = rate / ARRATE; in init_timetables()
585 OPL->DR_TABLE[i] = rate / DRRATE; in init_timetables()
587 for (i = 60; i < ARRAY_SIZE(OPL->AR_TABLE); i++) in init_timetables()
589 OPL->AR_TABLE[i] = EG_AED-1; in init_timetables()
590 OPL->DR_TABLE[i] = OPL->DR_TABLE[60]; in init_timetables()
595 ((double)(EG_ENT<<ENV_BITS) / OPL->AR_TABLE[i]) * (1000.0 / OPL->rate), in init_timetables()
596 ((double)(EG_ENT<<ENV_BITS) / OPL->DR_TABLE[i]) * (1000.0 / OPL->rate) )); in init_timetables()
723 static void OPL_initialize(FM_OPL *OPL) in OPL_initialize() argument
728 OPL->freqbase = (OPL->rate) ? ((double)OPL->clock / OPL->rate) / 72 : 0; in OPL_initialize()
730 OPL->TimerBase = 1.0/((double)OPL->clock / 72.0 ); in OPL_initialize()
732 init_timetables( OPL , OPL_ARRATE , OPL_DRRATE ); in OPL_initialize()
736 OPL->FN_TABLE[fn] = OPL->freqbase * fn * FREQ_RATE * (1<<7) / 2; in OPL_initialize()
739OPL->amsIncr = OPL->rate ? (double)AMS_ENT*(1<<AMS_SHIFT) / OPL->rate * 3.7 * ((double)OPL->clock/… in OPL_initialize()
740OPL->vibIncr = OPL->rate ? (double)VIB_ENT*(1<<VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/… in OPL_initialize()
744 static void OPLWriteReg(FM_OPL *OPL, int r, int v) in OPLWriteReg() argument
757 OPL->wavesel = v&0x20; in OPLWriteReg()
758 if(!OPL->wavesel) in OPLWriteReg()
762 for(c=0;c<OPL->max_ch;c++) in OPLWriteReg()
764 OPL->P_CH[c].SLOT[SLOT1].wavetable = &SIN_TABLE[0]; in OPLWriteReg()
765 OPL->P_CH[c].SLOT[SLOT2].wavetable = &SIN_TABLE[0]; in OPLWriteReg()
770 OPL->T[0] = (256-v)*4; in OPLWriteReg()
773 OPL->T[1] = (256-v)*16; in OPLWriteReg()
778 OPL_STATUS_RESET(OPL,0x7f); in OPLWriteReg()
785 OPL_STATUS_RESET(OPL,v&0x78); in OPLWriteReg()
786 OPL_STATUSMASK_SET(OPL,((~v)&0x78)|0x01); in OPLWriteReg()
788 if(OPL->st[1] != st2) in OPLWriteReg()
790 double interval = st2 ? (double)OPL->T[1]*OPL->TimerBase : 0.0; in OPLWriteReg()
791 OPL->st[1] = st2; in OPLWriteReg()
792 if (OPL->TimerHandler) { in OPLWriteReg()
793 (OPL->TimerHandler)(OPL->TimerParam, 1, interval); in OPLWriteReg()
797 if(OPL->st[0] != st1) in OPLWriteReg()
799 double interval = st1 ? (double)OPL->T[0]*OPL->TimerBase : 0.0; in OPLWriteReg()
800 OPL->st[0] = st1; in OPLWriteReg()
801 if (OPL->TimerHandler) { in OPLWriteReg()
802 (OPL->TimerHandler)(OPL->TimerParam, 0, interval); in OPLWriteReg()
812 set_mul(OPL,slot,v); in OPLWriteReg()
817 set_ksl_tl(OPL,slot,v); in OPLWriteReg()
822 set_ar_dr(OPL,slot,v); in OPLWriteReg()
827 set_sl_rr(OPL,slot,v); in OPLWriteReg()
835 uint8_t rkey = OPL->rhythm^v; in OPLWriteReg()
836 OPL->ams_table = &AMS_TABLE[v&0x80 ? AMS_ENT : 0]; in OPLWriteReg()
837 OPL->vib_table = &VIB_TABLE[v&0x40 ? VIB_ENT : 0]; in OPLWriteReg()
838 OPL->rhythm = v&0x3f; in OPLWriteReg()
839 if(OPL->rhythm&0x20) in OPLWriteReg()
849 OPL->P_CH[6].op1_out[0] = OPL->P_CH[6].op1_out[1] = 0; in OPLWriteReg()
850 OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT1]); in OPLWriteReg()
851 OPL_KEYON(&OPL->P_CH[6].SLOT[SLOT2]); in OPLWriteReg()
855 OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT1]); in OPLWriteReg()
856 OPL_KEYOFF(&OPL->P_CH[6].SLOT[SLOT2]); in OPLWriteReg()
862 if(v&0x08) OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT2]); in OPLWriteReg()
863 else OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT2]); in OPLWriteReg()
867 if(v&0x04) OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT1]); in OPLWriteReg()
868 else OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT1]); in OPLWriteReg()
873 if(v&0x02) OPL_KEYON(&OPL->P_CH[8].SLOT[SLOT2]); in OPLWriteReg()
874 else OPL_KEYOFF(&OPL->P_CH[8].SLOT[SLOT2]); in OPLWriteReg()
879 if(v&0x01) OPL_KEYON(&OPL->P_CH[7].SLOT[SLOT1]); in OPLWriteReg()
880 else OPL_KEYOFF(&OPL->P_CH[7].SLOT[SLOT1]); in OPLWriteReg()
888 CH = &OPL->P_CH[r&0x0f]; in OPLWriteReg()
920 CH->fc = OPL->FN_TABLE[fnum]>>blockRv; in OPLWriteReg()
922 if( (OPL->mode&0x40) && CH->block_fnum&0x100) CH->kcode |=1; in OPLWriteReg()
930 CH = &OPL->P_CH[r&0x0f]; in OPLWriteReg()
941 CH = &OPL->P_CH[slot/2]; in OPLWriteReg()
942 if(OPL->wavesel) in OPLWriteReg()
981 void YM3812UpdateOne(FM_OPL *OPL, int16_t *buffer, int length) in YM3812UpdateOne() argument
986 uint32_t amsCnt = OPL->amsCnt; in YM3812UpdateOne()
987 uint32_t vibCnt = OPL->vibCnt; in YM3812UpdateOne()
988 uint8_t rhythm = OPL->rhythm&0x20; in YM3812UpdateOne()
991 if( (void *)OPL != cur_chip ){ in YM3812UpdateOne()
992 cur_chip = (void *)OPL; in YM3812UpdateOne()
994 S_CH = OPL->P_CH; in YM3812UpdateOne()
1002 amsIncr = OPL->amsIncr; in YM3812UpdateOne()
1003 vibIncr = OPL->vibIncr; in YM3812UpdateOne()
1004 ams_table = OPL->ams_table; in YM3812UpdateOne()
1005 vib_table = OPL->vib_table; in YM3812UpdateOne()
1027 OPL->amsCnt = amsCnt; in YM3812UpdateOne()
1028 OPL->vibCnt = vibCnt; in YM3812UpdateOne()
1033 if( opl_dbg_opl[opl_dbg_chip] == OPL) break; in YM3812UpdateOne()
1040 static void OPLResetChip(FM_OPL *OPL) in OPLResetChip() argument
1046 OPL->mode = 0; /* normal mode */ in OPLResetChip()
1047 OPL_STATUS_RESET(OPL,0x7f); in OPLResetChip()
1049 OPLWriteReg(OPL,0x01,0); /* wabesel disable */ in OPLResetChip()
1050 OPLWriteReg(OPL,0x02,0); /* Timer1 */ in OPLResetChip()
1051 OPLWriteReg(OPL,0x03,0); /* Timer2 */ in OPLResetChip()
1052 OPLWriteReg(OPL,0x04,0); /* IRQ mask clear */ in OPLResetChip()
1053 for(i = 0xff ; i >= 0x20 ; i-- ) OPLWriteReg(OPL,i,0); in OPLResetChip()
1055 for( c = 0 ; c < OPL->max_ch ; c++ ) in OPLResetChip()
1057 OPL_CH *CH = &OPL->P_CH[c]; in OPLResetChip()
1076 FM_OPL *OPL; in OPLCreate() local
1089 OPL = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL); in OPLCreate()
1090 OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch; in OPLCreate()
1092 OPL->clock = clock; in OPLCreate()
1093 OPL->rate = rate; in OPLCreate()
1094 OPL->max_ch = max_ch; in OPLCreate()
1096 OPL_initialize(OPL); in OPLCreate()
1098 OPLResetChip(OPL); in OPLCreate()
1107 opl_dbg_opl[opl_dbg_maxchip] = OPL; in OPLCreate()
1117 return OPL; in OPLCreate()
1121 void OPLDestroy(FM_OPL *OPL) in OPLDestroy() argument
1131 free(OPL); in OPLDestroy()
1136 void OPLSetTimerHandler(FM_OPL *OPL, OPL_TIMERHANDLER TimerHandler, in OPLSetTimerHandler() argument
1139 OPL->TimerHandler = TimerHandler; in OPLSetTimerHandler()
1140 OPL->TimerParam = param; in OPLSetTimerHandler()
1144 int OPLWrite(FM_OPL *OPL,int a,int v) in OPLWrite() argument
1148 OPL->address = v & 0xff; in OPLWrite()
1156 if( opl_dbg_opl[opl_dbg_chip] == OPL) break; in OPLWrite()
1157 fprintf(opl_dbg_fp,"%c%c%c",0x10+opl_dbg_chip,OPL->address,v); in OPLWrite()
1160 OPLWriteReg(OPL,OPL->address,v); in OPLWrite()
1162 return OPL->status>>7; in OPLWrite()
1165 unsigned char OPLRead(FM_OPL *OPL,int a) in OPLRead() argument
1169 return OPL->status & (OPL->statusmask|0x80); in OPLRead()
1172 switch(OPL->address) in OPLRead()
1188 int OPLTimerOver(FM_OPL *OPL,int c) in OPLTimerOver() argument
1192 OPL_STATUS_SET(OPL,0x20); in OPLTimerOver()
1196 OPL_STATUS_SET(OPL,0x40); in OPLTimerOver()
1198 if( OPL->mode & 0x80 ) in OPLTimerOver()
1202 CSMKeyControll( &OPL->P_CH[ch] ); in OPLTimerOver()
1206 if (OPL->TimerHandler) { in OPLTimerOver()
1207 (OPL->TimerHandler)(OPL->TimerParam, c, in OPLTimerOver()
1208 (double)OPL->T[c] * OPL->TimerBase); in OPLTimerOver()
1210 return OPL->status>>7; in OPLTimerOver()