X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fsound%2Fym2612.c;h=56c363a1654f0a65b4ff602958336c1e242895c9;hb=b6d7ac70909e29ba8f40d6eaee53dd5b1bb71e52;hp=294d621931e37098bb8c5fe454d6d1a505810c81;hpb=db49317be10622fc8d2e766831483c7db2e17e0e;p=picodrive.git diff --git a/Pico/sound/ym2612.c b/Pico/sound/ym2612.c index 294d621..56c363a 100644 --- a/Pico/sound/ym2612.c +++ b/Pico/sound/ym2612.c @@ -381,7 +381,7 @@ static const UINT8 dt_tab[4 * 32]={ 5, 6, 6, 7, 8, 8, 9,10,11,12,13,14,16,16,16,16, /* FD=3 */ 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 6, 6, 7, - 8 , 8, 9,10,11,12,13,14,16,17,19,20,22,22,22,22 + 8 ,8, 9,10,11,12,13,14,16,17,19,20,22,22,22,22 }; @@ -1152,9 +1152,9 @@ static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: s UINT32 fn; int kc,fc; + blk = block_fnum >> 11; block_fnum = block_fnum*2 + lfo_fn_table_index_offset; - blk = (block_fnum&0x7000) >> 12; fn = block_fnum & 0xfff; /* keyscale code */ @@ -1203,10 +1203,14 @@ static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: s /* update phase increment and envelope generator */ INLINE void refresh_fc_eg_slot(FM_SLOT *SLOT, int fc, int kc) { - int ksr; + int ksr, fdt; /* (frequency) phase increment counter */ - SLOT->Incr = ((fc+SLOT->DT[kc])*SLOT->mul) >> 1; + fdt = fc+SLOT->DT[kc]; + /* detect overflow */ +// if (fdt < 0) fdt += fn_table[0x7ff*2] >> (7-blk-1); + if (fdt < 0) fdt += fn_table[0x7ff*2] >> 2; + SLOT->Incr = fdt*SLOT->mul >> 1; ksr = kc >> SLOT->KSR; if( SLOT->ksr != ksr ) @@ -1258,6 +1262,17 @@ INLINE void refresh_fc_eg_chan(FM_CH *CH) } } +INLINE void refresh_fc_eg_chan_sl3(void) +{ + if( ym2612.CH[2].SLOT[SLOT1].Incr==-1) + { + refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT1], ym2612.OPN.SL3.fc[1], ym2612.OPN.SL3.kcode[1] ); + refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT2], ym2612.OPN.SL3.fc[2], ym2612.OPN.SL3.kcode[2] ); + refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT3], ym2612.OPN.SL3.fc[0], ym2612.OPN.SL3.kcode[0] ); + refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT4], ym2612.CH[2].fc , ym2612.CH[2].kcode ); + } +} + /* initialize time tables */ static void init_timetables(const UINT8 *dttable) { @@ -1428,7 +1443,6 @@ static void OPNSetPres(int pres) ym2612.OPN.eg_timer_add = (1<>3; + UINT32 fn = (((UINT32)( (CH->fn_h)&7))<<8) + v; + UINT8 blk = CH->fn_h>>3; /* keyscale code */ CH->kcode = (blk<<2) | opn_fktable[fn >> 7]; /* phase increment counter */ @@ -1519,7 +1533,7 @@ static int OPNWriteReg(int r, int v) } break; case 1: /* 0xa4-0xa6 : FNUM2,BLK */ - ym2612.OPN.ST.fn_h = v&0x3f; + CH->fn_h = v&0x3f; ret = 0; break; case 2: /* 0xa8-0xaa : 3CH FNUM1 */ @@ -1619,16 +1633,10 @@ int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty) refresh_fc_eg_chan( &ym2612.CH[0] ); refresh_fc_eg_chan( &ym2612.CH[1] ); if( (ym2612.OPN.ST.mode & 0xc0) ) - { /* 3SLOT MODE */ - if( ym2612.CH[2].SLOT[SLOT1].Incr==-1) - { - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT1], ym2612.OPN.SL3.fc[1], ym2612.OPN.SL3.kcode[1] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT2], ym2612.OPN.SL3.fc[2], ym2612.OPN.SL3.kcode[2] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT3], ym2612.OPN.SL3.fc[0], ym2612.OPN.SL3.kcode[0] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT4], ym2612.CH[2].fc , ym2612.CH[2].kcode ); - } - } else refresh_fc_eg_chan( &ym2612.CH[2] ); + refresh_fc_eg_chan_sl3(); + else + refresh_fc_eg_chan( &ym2612.CH[2] ); refresh_fc_eg_chan( &ym2612.CH[3] ); refresh_fc_eg_chan( &ym2612.CH[4] ); refresh_fc_eg_chan( &ym2612.CH[5] ); @@ -1771,11 +1779,11 @@ int YM2612Write_(unsigned int a, unsigned int v) } ret=0; break; +#endif case 0x27: /* mode, timer control */ set_timers( v ); ret=0; break; -#endif case 0x28: /* key on / off */ { UINT8 c; @@ -1789,7 +1797,6 @@ int YM2612Write_(unsigned int a, unsigned int v) if(v&0x80) FM_KEYON(c,SLOT4); else FM_KEYOFF(c,SLOT4); break; } -#if 0 case 0x2a: /* DAC data (YM2612) */ ym2612.dacout = ((int)v - 0x80) << 6; /* level unknown (notaz: 8 seems to be too much) */ ret=0; @@ -1799,7 +1806,6 @@ int YM2612Write_(unsigned int a, unsigned int v) ym2612.dacen = v & 0x80; ret=0; break; -#endif default: break; } @@ -1827,12 +1833,7 @@ int YM2612Write_(unsigned int a, unsigned int v) ret = OPNWriteReg(addr, v); break; } -/* - if(ret) { - extern int Scanline; - dprintf("ymw [%i]", Scanline); - } -*/ + return ret; } @@ -1893,22 +1894,20 @@ typedef struct UINT32 eg_timer; UINT32 lfo_cnt; UINT16 lfo_ampm; - UINT8 fn_h; - UINT8 fn_h_sl3; + UINT16 unused2; UINT32 keyon_field; // 20 UINT32 kcode_fc_sl3_3; + UINT32 reserved[2]; } ym_save_addon; typedef struct { UINT16 block_fnum[6]; UINT16 block_fnum_sl3[3]; - UINT16 unused; + UINT16 reserved[7]; } ym_save_addon2; -//static YM2612 check_ym; - void YM2612PicoStateSave2(int tat, int tbt) { ym_save_addon_slot ss; @@ -1917,25 +1916,8 @@ void YM2612PicoStateSave2(int tat, int tbt) unsigned char *ptr; int c, s; - refresh_fc_eg_chan( &ym2612.CH[0] ); - refresh_fc_eg_chan( &ym2612.CH[1] ); - if( (ym2612.OPN.ST.mode & 0xc0) ) - { - /* 3SLOT MODE */ - if( ym2612.CH[2].SLOT[SLOT1].Incr==-1) - { - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT1], ym2612.OPN.SL3.fc[1], ym2612.OPN.SL3.kcode[1] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT2], ym2612.OPN.SL3.fc[2], ym2612.OPN.SL3.kcode[2] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT3], ym2612.OPN.SL3.fc[0], ym2612.OPN.SL3.kcode[0] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT4], ym2612.CH[2].fc , ym2612.CH[2].kcode ); - } - } else refresh_fc_eg_chan( &ym2612.CH[2] ); - refresh_fc_eg_chan( &ym2612.CH[3] ); - refresh_fc_eg_chan( &ym2612.CH[4] ); - refresh_fc_eg_chan( &ym2612.CH[5] ); - memset(&sa, 0, sizeof(sa)); -//memcpy(&check_ym, &ym2612, sizeof(ym2612)); + memset(&sa2, 0, sizeof(sa2)); // chans 1,2,3 ptr = &ym2612.REGS[0x0b8]; @@ -1978,15 +1960,12 @@ void YM2612PicoStateSave2(int tat, int tbt) sa.address = ym2612.OPN.ST.address; sa.status = ym2612.OPN.ST.status; sa.addr_A1 = ym2612.addr_A1; - sa.unused = 0; sa.TAT = tat; sa.TBT = tbt; sa.eg_cnt = ym2612.OPN.eg_cnt; sa.eg_timer = ym2612.OPN.eg_timer; sa.lfo_cnt = ym2612.OPN.lfo_cnt; sa.lfo_ampm = g_lfo_ampm; - sa.fn_h = ym2612.REGS[0xa4] = ym2612.OPN.ST.fn_h; - sa.fn_h_sl3 = ym2612.REGS[0xac] = ym2612.OPN.SL3.fn_h; memcpy(ptr, &sa, sizeof(sa)); // 0x30 max } @@ -2028,7 +2007,6 @@ int YM2612PicoStateLoad2(int *tat, int *tbt) ym2612.CH[c].SLOT[s].volume = ss.volume; ym2612.CH[c].SLOT[s].key = (sa.keyon_field & (1 << (c*4 + s))) ? 1 : 0; ym2612.CH[c].SLOT[s].ksr = (UINT8)-1; -//ym2612.CH[c].SLOT[s].Incr = check_ym.CH[c].SLOT[s].Incr; ptr += 6; } ym2612.CH[c].SLOT[SLOT1].Incr=-1; @@ -2049,7 +2027,6 @@ int YM2612PicoStateLoad2(int *tat, int *tbt) ym2612.CH[c].SLOT[s].volume = ss.volume; ym2612.CH[c].SLOT[s].key = (sa.keyon_field & (1 << (c*4 + s))) ? 1 : 0; ym2612.CH[c].SLOT[s].ksr = (UINT8)-1; -//ym2612.CH[c].SLOT[s].Incr = check_ym.CH[c].SLOT[s].Incr; ptr += 6; } ym2612.CH[c].SLOT[SLOT1].Incr=-1; @@ -2068,64 +2045,6 @@ int YM2612PicoStateLoad2(int *tat, int *tbt) ym2612.OPN.SL3.fc[c] = fn_table[fn*2]>>(7-blk); } -#if 0 - refresh_fc_eg_chan( &ym2612.CH[0] ); - refresh_fc_eg_chan( &ym2612.CH[1] ); - if( (ym2612.OPN.ST.mode & 0xc0) ) - { - /* 3SLOT MODE */ - if( ym2612.CH[2].SLOT[SLOT1].Incr==-1) - { - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT1], ym2612.OPN.SL3.fc[1], ym2612.OPN.SL3.kcode[1] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT2], ym2612.OPN.SL3.fc[2], ym2612.OPN.SL3.kcode[2] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT3], ym2612.OPN.SL3.fc[0], ym2612.OPN.SL3.kcode[0] ); - refresh_fc_eg_slot(&ym2612.CH[2].SLOT[SLOT4], ym2612.CH[2].fc , ym2612.CH[2].kcode ); - } - } else refresh_fc_eg_chan( &ym2612.CH[2] ); - refresh_fc_eg_chan( &ym2612.CH[3] ); - refresh_fc_eg_chan( &ym2612.CH[4] ); - refresh_fc_eg_chan( &ym2612.CH[5] ); - - for (c = 0; c < 6; c++) - { - for (s = 0; s < 4; s++) - { - int i; - unsigned char *chk = ((unsigned char *) &check_ym.CH[c].SLOT[s]); - unsigned char *res = ((unsigned char *) &ym2612.CH[c].SLOT[s]); - - for (i = 0; i < sizeof(check_ym.CH[0].SLOT[0]); i++) - { - if (i != 0x0c && chk[i] != res[i]) - printf("ch[%i].slot[%i].%03x: %02x vs %02x\n", c, s, i, chk[i], res[i]); - } - } - - { - int i; - unsigned char *chk = ((unsigned char *) &check_ym.CH[c].ALGO); - unsigned char *res = ((unsigned char *) &ym2612.CH[c].ALGO); - - for (i = 0; i < 8*4; i++) - { - if ((i < 4 || i > 0x0b) && chk[i] != res[i]) - printf("ch[%i].%03x: %02x vs %02x\n", c, i, chk[i], res[i]); - } - } - } - - for (c = 0; c < sizeof(ym2612.OPN); c++) - { - unsigned char *chk = ((unsigned char *) &check_ym.OPN); - unsigned char *res = ((unsigned char *) &ym2612.OPN); - - if (chk[c] != res[c]) - { - printf("OPN: %03x: %02x vs %02x\n", c, chk[c], res[c]); - } - } -#endif - return 0; }