Lines Matching +full:double +full:- +full:channel
3 ** File: fmopl.c -- software implementation of FM sound generator
41 /* -------------------- for debug --------------------- */
49 /* -------------------- preliminary define section --------------------- */
54 #define DELTAT_MIXING_LEVEL (1) /* DELTA-T ADPCM MIXING LEVEL */
59 #define FREQ_RATE (1<<(FREQ_BITS-20))
63 #define OPL_OUTSB (TL_BITS+3-16) /* OPL output final shift 16bit */
65 #define OPL_MINOUT (-0x8000<<OPL_OUTSB)
67 /* -------------------- quality selection --------------------- */
91 #define VIB_SHIFT (32-9)
93 #define AMS_SHIFT (32-9)
97 /* -------------------- local defines , macros --------------------- */
99 /* register number to channel number , slot offset */
108 /* -------------------- tables --------------------- */
111 0, 2, 4, 1, 3, 5,-1,-1,
112 6, 8,10, 7, 9,11,-1,-1,
113 12,14,16,13,15,17,-1,-1,
114 -1,-1,-1,-1,-1,-1,-1,-1
166 /* 0 - 15: 0, 3, 6, 9,12,15,18,21,24,27,30,33,36,39,42,93 (dB)*/
177 /* TL_TABLE[ TL_MAX to TL_MAX+TL_MAX-1 ] : minus section */
204 /* -------------------- static state --------------------- */
237 /* --------------------- subroutines --------------------- */
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()
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()
279 OPL->statusmask = flag; in OPL_STATUSMASK_SET()
285 /* ----- key on ----- */
289 SLOT->Cnt = 0; in OPL_KEYON()
291 SLOT->evm = ENV_MOD_AR; in OPL_KEYON()
292 SLOT->evs = SLOT->evsa; in OPL_KEYON()
293 SLOT->evc = EG_AST; in OPL_KEYON()
294 SLOT->eve = EG_AED; in OPL_KEYON()
296 /* ----- key off ----- */
299 if( SLOT->evm > ENV_MOD_RR) in OPL_KEYOFF()
302 SLOT->evm = ENV_MOD_RR; in OPL_KEYOFF()
303 if( !(SLOT->evc&EG_DST) ) in OPL_KEYOFF()
304 //SLOT->evc = (ENV_CURVE[SLOT->evc>>ENV_BITS]<<ENV_BITS) + EG_DST; in OPL_KEYOFF()
305 SLOT->evc = EG_DST; in OPL_KEYOFF()
306 SLOT->eve = EG_DED; in OPL_KEYOFF()
307 SLOT->evs = SLOT->evsr; in OPL_KEYOFF()
311 /* ---------- calcrate Envelope Generator & Phase Generator ---------- */
316 if( (SLOT->evc+=SLOT->evs) >= SLOT->eve ) in OPL_CALC_SLOT()
318 switch( SLOT->evm ){ in OPL_CALC_SLOT()
319 case ENV_MOD_AR: /* ATTACK -> DECAY1 */ in OPL_CALC_SLOT()
321 SLOT->evm = ENV_MOD_DR; in OPL_CALC_SLOT()
322 SLOT->evc = EG_DST; in OPL_CALC_SLOT()
323 SLOT->eve = SLOT->SL; in OPL_CALC_SLOT()
324 SLOT->evs = SLOT->evsd; in OPL_CALC_SLOT()
326 case ENV_MOD_DR: /* DECAY -> SL or RR */ in OPL_CALC_SLOT()
327 SLOT->evc = SLOT->SL; in OPL_CALC_SLOT()
328 SLOT->eve = EG_DED; in OPL_CALC_SLOT()
329 if(SLOT->eg_typ) in OPL_CALC_SLOT()
331 SLOT->evs = 0; in OPL_CALC_SLOT()
335 SLOT->evm = ENV_MOD_RR; in OPL_CALC_SLOT()
336 SLOT->evs = SLOT->evsr; in OPL_CALC_SLOT()
339 case ENV_MOD_RR: /* RR -> OFF */ in OPL_CALC_SLOT()
340 SLOT->evc = EG_OFF; in OPL_CALC_SLOT()
341 SLOT->eve = EG_OFF+1; in OPL_CALC_SLOT()
342 SLOT->evs = 0; in OPL_CALC_SLOT()
347 return SLOT->TLL+ENV_CURVE[SLOT->evc>>ENV_BITS]+(SLOT->ams ? ams : 0); in OPL_CALC_SLOT()
354 CH->connect1 = CH->CON ? carrier : &feedback2; in set_algorithm()
355 CH->connect2 = carrier; in set_algorithm()
358 /* ---------- frequency counter for operator update ---------- */
364 SLOT->Incr = CH->fc * SLOT->mul; in CALC_FCSLOT()
365 ksr = CH->kcode >> SLOT->KSR; in CALC_FCSLOT()
367 if( SLOT->ksr != ksr ) in CALC_FCSLOT()
369 SLOT->ksr = ksr; in CALC_FCSLOT()
371 SLOT->evsa = SLOT->AR[ksr]; in CALC_FCSLOT()
372 SLOT->evsd = SLOT->DR[ksr]; in CALC_FCSLOT()
373 SLOT->evsr = SLOT->RR[ksr]; in CALC_FCSLOT()
375 SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl); in CALC_FCSLOT()
378 /* set multi,am,vib,EG-TYP,KSR,mul */
381 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_mul()
382 OPL_SLOT *SLOT = &CH->SLOT[slot&1]; in set_mul()
384 SLOT->mul = MUL_TABLE[v&0x0f]; in set_mul()
385 SLOT->KSR = (v&0x10) ? 0 : 2; in set_mul()
386 SLOT->eg_typ = (v&0x20)>>5; in set_mul()
387 SLOT->vib = (v&0x40); in set_mul()
388 SLOT->ams = (v&0x80); in set_mul()
395 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_ksl_tl()
396 OPL_SLOT *SLOT = &CH->SLOT[slot&1]; in set_ksl_tl()
399 SLOT->ksl = ksl ? 3-ksl : 31; in set_ksl_tl()
400 SLOT->TL = (v&0x3f)*(0.75/EG_STEP); /* 0.75db step */ in set_ksl_tl()
402 if( !(OPL->mode&0x80) ) in set_ksl_tl()
404 SLOT->TLL = SLOT->TL + (CH->ksl_base>>SLOT->ksl); in set_ksl_tl()
411 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_ar_dr()
412 OPL_SLOT *SLOT = &CH->SLOT[slot&1]; in set_ar_dr()
416 SLOT->AR = ar ? &OPL->AR_TABLE[ar<<2] : RATE_0; in set_ar_dr()
417 SLOT->evsa = SLOT->AR[SLOT->ksr]; in set_ar_dr()
418 if( SLOT->evm == ENV_MOD_AR ) SLOT->evs = SLOT->evsa; in set_ar_dr()
420 SLOT->DR = dr ? &OPL->DR_TABLE[dr<<2] : RATE_0; in set_ar_dr()
421 SLOT->evsd = SLOT->DR[SLOT->ksr]; in set_ar_dr()
422 if( SLOT->evm == ENV_MOD_DR ) SLOT->evs = SLOT->evsd; in set_ar_dr()
428 OPL_CH *CH = &OPL->P_CH[slot/2]; in set_sl_rr()
429 OPL_SLOT *SLOT = &CH->SLOT[slot&1]; in set_sl_rr()
433 SLOT->SL = SL_TABLE[sl]; in set_sl_rr()
434 if( SLOT->evm == ENV_MOD_DR ) SLOT->eve = SLOT->SL; in set_sl_rr()
435 SLOT->RR = &OPL->DR_TABLE[rr<<2]; in set_sl_rr()
436 SLOT->evsr = SLOT->RR[SLOT->ksr]; in set_sl_rr()
437 if( SLOT->evm == ENV_MOD_RR ) SLOT->evs = SLOT->evsr; in set_sl_rr()
441 #define OP_OUT(slot,env,con) slot->wavetable[((slot->Cnt+con)/(0x1000000/SIN_ENT))&(SIN_ENT-1)][e…
442 /* ---------- calcrate one of channel ---------- */
450 SLOT = &CH->SLOT[SLOT1]; in OPL_CALC_CH()
452 if( env_out < EG_ENT-1 ) in OPL_CALC_CH()
455 if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); in OPL_CALC_CH()
456 else SLOT->Cnt += SLOT->Incr; in OPL_CALC_CH()
458 if(CH->FB) in OPL_CALC_CH()
460 int feedback1 = (CH->op1_out[0]+CH->op1_out[1])>>CH->FB; in OPL_CALC_CH()
461 CH->op1_out[1] = CH->op1_out[0]; in OPL_CALC_CH()
462 *CH->connect1 += CH->op1_out[0] = OP_OUT(SLOT,env_out,feedback1); in OPL_CALC_CH()
466 *CH->connect1 += OP_OUT(SLOT,env_out,0); in OPL_CALC_CH()
470 CH->op1_out[1] = CH->op1_out[0]; in OPL_CALC_CH()
471 CH->op1_out[0] = 0; in OPL_CALC_CH()
474 SLOT = &CH->SLOT[SLOT2]; in OPL_CALC_CH()
476 if( env_out < EG_ENT-1 ) in OPL_CALC_CH()
479 if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); in OPL_CALC_CH()
480 else SLOT->Cnt += SLOT->Incr; in OPL_CALC_CH()
486 /* ---------- calcrate rhythm block ---------- */
502 if( env_out < EG_ENT-1 ) in OPL_CALC_RH()
505 if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); in OPL_CALC_RH()
506 else SLOT->Cnt += SLOT->Incr; in OPL_CALC_RH()
527 if( env_out < EG_ENT-1 ) in OPL_CALC_RH()
530 if(SLOT->vib) SLOT->Cnt += (SLOT->Incr*vib/VIB_RATE); in OPL_CALC_RH()
531 else SLOT->Cnt += SLOT->Incr; in OPL_CALC_RH()
546 if(SLOT7_1->vib) SLOT7_1->Cnt += (2*SLOT7_1->Incr*vib/VIB_RATE); in OPL_CALC_RH()
547 else SLOT7_1->Cnt += 2*SLOT7_1->Incr; in OPL_CALC_RH()
548 if(SLOT7_2->vib) SLOT7_2->Cnt += ((CH[7].fc*8)*vib/VIB_RATE); in OPL_CALC_RH()
549 else SLOT7_2->Cnt += (CH[7].fc*8); in OPL_CALC_RH()
550 if(SLOT8_1->vib) SLOT8_1->Cnt += (SLOT8_1->Incr*vib/VIB_RATE); in OPL_CALC_RH()
551 else SLOT8_1->Cnt += SLOT8_1->Incr; in OPL_CALC_RH()
552 if(SLOT8_2->vib) SLOT8_2->Cnt += ((CH[8].fc*48)*vib/VIB_RATE); in OPL_CALC_RH()
553 else SLOT8_2->Cnt += (CH[8].fc*48); in OPL_CALC_RH()
558 if( env_sd < EG_ENT-1 ) in OPL_CALC_RH()
561 if( env_tam < EG_ENT-1 ) in OPL_CALC_RH()
563 /* TOP-CY */ in OPL_CALC_RH()
564 if( env_top < EG_ENT-1 ) in OPL_CALC_RH()
567 if( env_hh < EG_ENT-1 ) in OPL_CALC_RH()
571 /* ----------- initialize time tabls ----------- */
575 double rate; in init_timetables()
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()
581 if( i < 60 ) rate *= 1.0+(i&3)*0.25; /* b0-1 : x1 , x1.25 , x1.5 , x1.75 */ in init_timetables()
582 rate *= 1<<((i>>2)-1); /* b2-5 : shift bit */ in init_timetables()
583 rate *= (double)(EG_ENT<<ENV_BITS); 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()
601 /* ---------- generic table initialize ---------- */
605 double rate; in OPLOpenTable()
607 double pom; in OPLOpenTable()
632 for (t = 0;t < EG_ENT-1 ;t++){ in OPLOpenTable()
633 rate = ((1<<TL_BITS)-1)/pow(10,EG_STEP*t/20); /* dB -> voltage */ in OPLOpenTable()
635 TL_TABLE[TL_MAX+t] = -TL_TABLE[t]; in OPLOpenTable()
639 for ( t = EG_ENT-1; t < TL_MAX ;t++){ in OPLOpenTable()
645 SIN_TABLE[0] = SIN_TABLE[SIN_ENT/2] = &TL_TABLE[EG_ENT-1]; in OPLOpenTable()
651 /* degree 0 - 90 , degree 180 - 90 : plus section */ in OPLOpenTable()
652 SIN_TABLE[ s] = SIN_TABLE[SIN_ENT/2-s] = &TL_TABLE[j]; in OPLOpenTable()
653 /* degree 180 - 270 , degree 360 - 270 : minus section */ in OPLOpenTable()
654 SIN_TABLE[SIN_ENT/2+s] = SIN_TABLE[SIN_ENT -s] = &TL_TABLE[TL_MAX+j]; in OPLOpenTable()
655 /* LOG(LOG_INF,("sin(%3d) = %f:%f db\n",s,pom,(double)j * EG_STEP));*/ in OPLOpenTable()
664 /* envelope counter -> envelope output table */ in OPLOpenTable()
668 pom = pow( ((double)(EG_ENT-1-i)/EG_ENT) , 8 ) * EG_ENT; in OPLOpenTable()
669 /* if( pom >= EG_ENT ) pom = EG_ENT-1; */ in OPLOpenTable()
675 ENV_CURVE[EG_OFF>>ENV_BITS]= EG_ENT-1; in OPLOpenTable()
687 pom = (double)VIB_RATE*0.06*sin(2*PI*i/VIB_ENT); /* +-100sect step */ in OPLOpenTable()
688 VIB_TABLE[i] = VIB_RATE + (pom*0.07); /* +- 7cent */ in OPLOpenTable()
689 VIB_TABLE[VIB_ENT+i] = VIB_RATE + (pom*0.14); /* +-14cent */ in OPLOpenTable()
708 OPL_SLOT *slot1 = &CH->SLOT[SLOT1]; in CSMKeyControll()
709 OPL_SLOT *slot2 = &CH->SLOT[SLOT2]; in CSMKeyControll()
714 slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl); in CSMKeyControll()
715 slot1->TLL = slot1->TL + (CH->ksl_base>>slot1->ksl); in CSMKeyControll()
717 CH->op1_out[0] = CH->op1_out[1] = 0; in CSMKeyControll()
722 /* ---------- opl initialize ---------- */
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()
733 /* make fnumber -> increment counter table */ in OPL_initialize()
736 OPL->FN_TABLE[fn] = OPL->freqbase * fn * FREQ_RATE * (1<<7) / 2; in OPL_initialize()
739 …OPL->amsIncr = OPL->rate ? (double)AMS_ENT*(1<<AMS_SHIFT) / OPL->rate * 3.7 * ((double)OPL->clock/… in OPL_initialize()
740 …OPL->vibIncr = OPL->rate ? (double)VIB_ENT*(1<<VIB_SHIFT) / OPL->rate * 6.4 * ((double)OPL->clock/… in OPL_initialize()
743 /* ---------- write a OPL registers ---------- */
752 case 0x00: /* 00-1f:control */ in OPLWriteReg()
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()
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()
811 if(slot == -1) return; in OPLWriteReg()
816 if(slot == -1) return; in OPLWriteReg()
821 if(slot == -1) return; in OPLWriteReg()
826 if(slot == -1) return; 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()
870 /* TOP-CY key on/off */ 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()
890 { /* a0-a8 */ in OPLWriteReg()
891 block_fnum = (CH->block_fnum&0x1f00) | v; in OPLWriteReg()
894 { /* b0-b8 */ in OPLWriteReg()
896 block_fnum = ((v&0x1f)<<8) | (CH->block_fnum&0xff); in OPLWriteReg()
897 if(CH->keyon != keyon) in OPLWriteReg()
899 if( (CH->keyon=keyon) ) in OPLWriteReg()
901 CH->op1_out[0] = CH->op1_out[1] = 0; in OPLWriteReg()
902 OPL_KEYON(&CH->SLOT[SLOT1]); in OPLWriteReg()
903 OPL_KEYON(&CH->SLOT[SLOT2]); in OPLWriteReg()
907 OPL_KEYOFF(&CH->SLOT[SLOT1]); in OPLWriteReg()
908 OPL_KEYOFF(&CH->SLOT[SLOT2]); in OPLWriteReg()
913 if(CH->block_fnum != block_fnum) in OPLWriteReg()
915 int blockRv = 7-(block_fnum>>10); in OPLWriteReg()
917 CH->block_fnum = block_fnum; in OPLWriteReg()
919 CH->ksl_base = KSL_TABLE[block_fnum>>6]; in OPLWriteReg()
920 CH->fc = OPL->FN_TABLE[fnum]>>blockRv; in OPLWriteReg()
921 CH->kcode = CH->block_fnum>>9; in OPLWriteReg()
922 if( (OPL->mode&0x40) && CH->block_fnum&0x100) CH->kcode |=1; in OPLWriteReg()
923 CALC_FCSLOT(CH,&CH->SLOT[SLOT1]); in OPLWriteReg()
924 CALC_FCSLOT(CH,&CH->SLOT[SLOT2]); in OPLWriteReg()
930 CH = &OPL->P_CH[r&0x0f]; in OPLWriteReg()
933 CH->FB = feedback ? (8+1) - feedback : 0; in OPLWriteReg()
934 CH->CON = v&1; in OPLWriteReg()
940 if(slot == -1) return; in OPLWriteReg()
941 CH = &OPL->P_CH[slot/2]; in OPLWriteReg()
942 if(OPL->wavesel) in OPLWriteReg()
945 CH->SLOT[slot&1].wavetable = &SIN_TABLE[(v&0x03)*SIN_ENT]; in OPLWriteReg()
961 num_lock--; in OPL_LockTable()
962 return -1; in OPL_LockTable()
969 if(num_lock) num_lock--; in OPL_UnLockTable()
980 /* ---------- update one of chip ----------- */
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()
993 /* channel pointers */ 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()
1010 /* channel A channel B channel C */ in YM3812UpdateOne()
1027 OPL->amsCnt = amsCnt; in YM3812UpdateOne()
1028 OPL->vibCnt = vibCnt; in YM3812UpdateOne()
1039 /* ---------- reset one of chip ---------- */
1046 OPL->mode = 0; /* normal mode */ 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()
1058 /* OPL->P_CH[c].PAN = OPN_CENTER; */ in OPLResetChip()
1062 CH->SLOT[s].wavetable = &SIN_TABLE[0]; in OPLResetChip()
1063 /* CH->SLOT[s].evm = ENV_MOD_RR; */ in OPLResetChip()
1064 CH->SLOT[s].evc = EG_OFF; in OPLResetChip()
1065 CH->SLOT[s].eve = EG_OFF+1; in OPLResetChip()
1066 CH->SLOT[s].evs = 0; in OPLResetChip()
1071 /* ---------- Create one of virtual YM3812 ---------- */
1080 if( OPL_LockTable() ==-1) return NULL; in OPLCreate()
1090 OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch; in OPLCreate()
1091 /* set channel state pointer */ in OPLCreate()
1092 OPL->clock = clock; in OPLCreate()
1093 OPL->rate = rate; in OPLCreate()
1094 OPL->max_ch = max_ch; in OPLCreate()
1120 /* ---------- Destroy one of virtual YM3812 ---------- */
1134 /* ---------- Option handlers ---------- */
1139 OPL->TimerHandler = TimerHandler; in OPLSetTimerHandler()
1140 OPL->TimerParam = param; in OPLSetTimerHandler()
1143 /* ---------- YM3812 I/O interface ---------- */
1148 OPL->address = v & 0xff; 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()
1169 return OPL->status & (OPL->statusmask|0x80); in OPLRead()
1172 switch(OPL->address) in OPLRead()
1177 case 0x0f: /* ADPCM-DATA */ in OPLRead()
1182 case 0x1a: /* PCM-DATA */ in OPLRead()
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()