--- ym2151.c.orig 2004-10-28 02:08:12.000000000 -0700 +++ ym2151.c 2004-10-30 02:13:25.551609448 -0700 @@ -2174,6 +2174,7 @@ if (op->pms) /* only when phase modulation from LFO is enabled for this channel */ { INT32 mod_ind = PSG->lfp; /* -128..+127 (8bits signed) */ + int steve = 0; if (op->pms < 6) mod_ind >>= (6 - op->pms); else @@ -2182,7 +2183,25 @@ if (mod_ind) { UINT32 kc_channel = op->kc_i + mod_ind; + INT32 steve_channel = op->kc_i + mod_ind; + if(steve_channel < 0) { + kc_channel = 0; + printf("steve_channel is %d, resetting kc_channel to zero\n",steve_channel); + } + printf("op kc_i is %x\n",op->kc_i); + printf("mod_ind is %x\n",mod_ind); (op+0)->phase += ( (PSG->freq[ kc_channel + (op+0)->dt2 ] + (op+0)->dt1) * (op+0)->mul ) >> 1; + steve = (op+1)->phase; + printf("op+1 phase is %x\n",steve); + printf("kc_channel is %x\n",kc_channel); + steve = (op+1)->dt2; + printf("op+1 dt2 is %x\n",steve); + steve = (op+1)->dt1; + printf("op+1 dt1 is %x\n",steve); + steve = (op+1)->mul; + printf("op+1 mul is %x\n",steve); + steve = (PSG->freq[ kc_channel + (op+1)->dt2 ]); + printf("PSG freq is %x\n",steve); (op+1)->phase += ( (PSG->freq[ kc_channel + (op+1)->dt2 ] + (op+1)->dt1) * (op+1)->mul ) >> 1; (op+2)->phase += ( (PSG->freq[ kc_channel + (op+2)->dt2 ] + (op+2)->dt1) * (op+2)->mul ) >> 1; (op+3)->phase += ( (PSG->freq[ kc_channel + (op+3)->dt2 ] + (op+3)->dt1) * (op+3)->mul ) >> 1;