From 324bd6852ec278f516538413b4ccf5b7e3356372 Mon Sep 17 00:00:00 2001 From: kub Date: Wed, 22 Apr 2020 21:40:05 +0200 Subject: [PATCH] audio: add option to switch off SSG-EG --- pico/pico.h | 1 + pico/sound/sound.c | 2 +- pico/sound/ym2612.c | 15 ++++++++------- pico/sound/ym2612.h | 10 +++++----- platform/common/menu_pico.c | 1 + platform/common/menu_pico.h | 1 + platform/gp2x/940ctl.c | 4 ++-- platform/gp2x/940ctl.h | 2 +- platform/gp2x/code940/940.c | 2 +- 9 files changed, 21 insertions(+), 17 deletions(-) diff --git a/pico/pico.h b/pico/pico.h index efc30e5f..d8c5959c 100644 --- a/pico/pico.h +++ b/pico/pico.h @@ -73,6 +73,7 @@ extern void *p32x_bios_g, *p32x_bios_m, *p32x_bios_s; #define POPT_EN_32X (1<<20) // x0 0000 #define POPT_EN_PWM (1<<21) #define POPT_PWM_IRQ_OPT (1<<22) +#define POPT_DIS_FM_SSGEG (1<<23) #define PAHW_MCD (1<<0) #define PAHW_32X (1<<1) diff --git a/pico/sound/sound.c b/pico/sound/sound.c index eb10f36b..54521601 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -48,7 +48,7 @@ void PsndRerate(int preserve_state) ym2612_pack_state(); memcpy(state, YM2612GetRegs(), 0x204); } - YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PicoIn.sndRate); + YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PicoIn.sndRate, !(PicoIn.opt&POPT_DIS_FM_SSGEG)); if (preserve_state) { // feed it back it's own registers, just like after loading state memcpy(YM2612GetRegs(), state, 0x204); diff --git a/pico/sound/ym2612.c b/pico/sound/ym2612.c index cb4f8c7d..622fff0b 100644 --- a/pico/sound/ym2612.c +++ b/pico/sound/ym2612.c @@ -1820,17 +1820,17 @@ int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty) // flags: stereo, ssg_enabled, disabled, _, pan_r, pan_l chan_render_prep(); #define BIT_IF(v,b,c) { v &= ~(1<<(b)); if (c) v |= 1<<(b); } - BIT_IF(flags, 1, (ym2612.ssg_mask & 0x00000f)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0x00000f) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0x00000f) active_chs |= chan_render(buffer, length, 0, flags|((pan&0x003)<<4)) << 0; - BIT_IF(flags, 1, (ym2612.ssg_mask & 0x0000f0)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0x0000f0) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0x0000f0) active_chs |= chan_render(buffer, length, 1, flags|((pan&0x00c)<<2)) << 1; - BIT_IF(flags, 1, (ym2612.ssg_mask & 0x000f00)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0x000f00) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0x000f00) active_chs |= chan_render(buffer, length, 2, flags|((pan&0x030) )) << 2; - BIT_IF(flags, 1, (ym2612.ssg_mask & 0x00f000)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0x00f000) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0x00f000) active_chs |= chan_render(buffer, length, 3, flags|((pan&0x0c0)>>2)) << 3; - BIT_IF(flags, 1, (ym2612.ssg_mask & 0x0f0000)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0x0f0000) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0x0f0000) active_chs |= chan_render(buffer, length, 4, flags|((pan&0x300)>>4)) << 4; - BIT_IF(flags, 1, (ym2612.ssg_mask & 0xf00000)); + BIT_IF(flags, 1, (ym2612.ssg_mask & 0xf00000) && (ym2612.OPN.ST.flags & 1)); if (ym2612.slot_mask & 0xf00000) active_chs |= chan_render(buffer, length, 5, flags|((pan&0xc00)>>6)|(!!ym2612.dacen<<2)) << 5; #undef BIT_IF chan_render_finish(); @@ -1840,13 +1840,14 @@ int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty) /* initialize YM2612 emulator */ -void YM2612Init_(int clock, int rate) +void YM2612Init_(int clock, int rate, int ssg) { memset(&ym2612, 0, sizeof(ym2612)); init_tables(); ym2612.OPN.ST.clock = clock; ym2612.OPN.ST.rate = rate; + ym2612.OPN.ST.flags = (ssg ? 1:0); OPNSetPres( 6*24 ); diff --git a/pico/sound/ym2612.h b/pico/sound/ym2612.h index b614790c..e73c9732 100644 --- a/pico/sound/ym2612.h +++ b/pico/sound/ym2612.h @@ -95,7 +95,7 @@ typedef struct UINT8 address; /* 10 address register | need_save */ UINT8 status; /* 11 status flag | need_save */ UINT8 mode; /* mode CSM / 3SLOT */ - UINT8 pad; + UINT8 flags; /* operational flags */ int TA; /* timer a */ int TAC; /* timer a maxval */ int TAT; /* timer a ticker | need_save */ @@ -161,7 +161,7 @@ typedef struct extern YM2612 ym2612; #endif -void YM2612Init_(int baseclock, int rate); +void YM2612Init_(int baseclock, int rate, int ssg); void YM2612ResetChip_(void); int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty); @@ -183,9 +183,9 @@ int YM2612PicoStateLoad2(int *tat, int *tbt); #else /* GP2X specific */ #include "../../platform/gp2x/940ctl.h" -#define YM2612Init(baseclock,rate) do { \ - if (PicoIn.opt&POPT_EXT_FM) YM2612Init_940(baseclock, rate); \ - else YM2612Init_(baseclock, rate); \ +#define YM2612Init(baseclock,rate,ssg) do { \ + if (PicoIn.opt&POPT_EXT_FM) YM2612Init_940(baseclock, rate, ssg); \ + else YM2612Init_(baseclock, rate, ssg); \ } while (0) #define YM2612ResetChip() do { \ if (PicoIn.opt&POPT_EXT_FM) YM2612ResetChip_940(); \ diff --git a/platform/common/menu_pico.c b/platform/common/menu_pico.c index 327190a5..882aef92 100644 --- a/platform/common/menu_pico.c +++ b/platform/common/menu_pico.c @@ -499,6 +499,7 @@ static menu_entry e_menu_adv_options[] = mee_range_h ("Overclock M68k (%)", MA_OPT2_OVERCLOCK_M68K,currentConfig.overclock_68k, 0, 1000, h_ovrclk), mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoIn.opt, POPT_EN_Z80), mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoIn.opt, POPT_EN_FM), + mee_onoff ("Disable YM2612 SSG-EG", MA_OPT2_DISABLE_YM_SSG,PicoIn.opt, POPT_DIS_FM_SSGEG), mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG), mee_onoff ("gzip savestates", MA_OPT2_GZIP_STATES, currentConfig.EmuOpt, EOPT_GZIP_SAVES), mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG), diff --git a/platform/common/menu_pico.h b/platform/common/menu_pico.h index 4c0bbdd1..d15113fc 100644 --- a/platform/common/menu_pico.h +++ b/platform/common/menu_pico.h @@ -48,6 +48,7 @@ typedef enum MA_OPT2_VSYNC, MA_OPT2_ENABLE_Z80, MA_OPT2_ENABLE_YM2612, + MA_OPT2_DISABLE_YM_SSG, MA_OPT2_ENABLE_SN76496, MA_OPT2_GZIP_STATES, MA_OPT2_NO_LAST_ROM, diff --git a/platform/gp2x/940ctl.c b/platform/gp2x/940ctl.c index 2afba0d9..cd3fcdc3 100644 --- a/platform/gp2x/940ctl.c +++ b/platform/gp2x/940ctl.c @@ -282,7 +282,7 @@ void sharedmem940_finish(void) } -void YM2612Init_940(int baseclock, int rate) +void YM2612Init_940(int baseclock, int rate, int ssg) { static int oldrate; @@ -339,7 +339,7 @@ void YM2612Init_940(int baseclock, int rate) memset(shared_ctl, 0, sizeof(*shared_ctl)); /* cause local ym2612 to init REGS */ - YM2612Init_(baseclock, rate); + YM2612Init_(baseclock, rate, ssg); internal_reset(); diff --git a/platform/gp2x/940ctl.h b/platform/gp2x/940ctl.h index 5b789dad..dba6cc70 100644 --- a/platform/gp2x/940ctl.h +++ b/platform/gp2x/940ctl.h @@ -1,7 +1,7 @@ void sharedmem940_init(void); void sharedmem940_finish(void); -void YM2612Init_940(int baseclock, int rate); +void YM2612Init_940(int baseclock, int rate, int ssg); void YM2612ResetChip_940(void); int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty); diff --git a/platform/gp2x/code940/940.c b/platform/gp2x/code940/940.c index f79db1e5..db51fdc9 100644 --- a/platform/gp2x/code940/940.c +++ b/platform/gp2x/code940/940.c @@ -167,7 +167,7 @@ void Main940(void) case JOB940_INITALL: /* ym2612 */ shared_ctl->writebuff0[0] = shared_ctl->writebuff1[0] = 0xffff; - YM2612Init_(shared_ctl->baseclock, shared_ctl->rate); + YM2612Init_(shared_ctl->baseclock, shared_ctl->rate, 0); /* Helix mp3 decoder */ __malloc_init(); shared_data->mp3dec = MP3InitDecoder(); -- 2.39.5