From 021e47b37557361ec880c92620c7cc1292d2f2c6 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 23 Sep 2013 20:01:37 +0300 Subject: [PATCH] cd: pcm: tune addr reload fahrenheit.. --- pico/cd/mcd.c | 1 + pico/cd/pcm.c | 33 ++++++++++++++++----------------- pico/pico_int.h | 3 ++- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/pico/cd/mcd.c b/pico/cd/mcd.c index ef8d8f21..6a978f8c 100644 --- a/pico/cd/mcd.c +++ b/pico/cd/mcd.c @@ -327,6 +327,7 @@ void pcd_state_loaded(void) memset(Pico_mcd->pcm_mixbuf, 0, sizeof(Pico_mcd->pcm_mixbuf)); Pico_mcd->pcm_mixbuf_dirty = 0; Pico_mcd->pcm_mixpos = 0; + Pico_mcd->pcm_regs_dirty = 1; // old savestates.. cycles = pcd_cycles_m68k_to_s68k(SekCycleAim); diff --git a/pico/cd/pcm.c b/pico/cd/pcm.c index a1276f9c..77bfa300 100644 --- a/pico/cd/pcm.c +++ b/pico/cd/pcm.c @@ -6,7 +6,6 @@ * See COPYING file in the top-level directory. */ -#include #include "../pico_int.h" #define PCM_STEP_SHIFT 11 @@ -30,19 +29,11 @@ void pcd_pcm_write(unsigned int a, unsigned int d) Pico_mcd->pcm.control = d; elprintf(EL_CD, "pcm control %02x", Pico_mcd->pcm.control); } - else if (a == 8 && Pico_mcd->pcm.enabled != (u_char)~d) + else if (a == 8) { - // sound on/off - int was_enabled = Pico_mcd->pcm.enabled; - int i; - - for (i = 0; i < 8; i++) - if (!(was_enabled & (1 << i))) - Pico_mcd->pcm.ch[i].addr = - Pico_mcd->pcm.ch[i].regs[6] << (PCM_STEP_SHIFT + 8); - Pico_mcd->pcm.enabled = ~d; } + Pico_mcd->pcm_regs_dirty = 1; } unsigned int pcd_pcm_read(unsigned int a) @@ -65,29 +56,37 @@ void pcd_pcm_sync(unsigned int to) struct pcm_chan *ch; unsigned int addr; int c, s, steps; + int enabled; int *out; if ((int)(to - cycles) < 384) return; steps = (to - cycles) / 384; + if (Pico_mcd->pcm_mixpos + steps > PCM_MIXBUF_LEN) + // shouldn't happen, but occasionally does + steps = PCM_MIXBUF_LEN - Pico_mcd->pcm_mixpos; // PCM disabled or all channels off - if (!(Pico_mcd->pcm.control & 0x80) || !Pico_mcd->pcm.enabled) + enabled = Pico_mcd->pcm.enabled; + if (!(Pico_mcd->pcm.control & 0x80)) + enabled = 0; + if (!enabled && !Pico_mcd->pcm_regs_dirty) goto end; out = Pico_mcd->pcm_mixbuf + Pico_mcd->pcm_mixpos * 2; Pico_mcd->pcm_mixbuf_dirty = 1; - if (Pico_mcd->pcm_mixpos + steps > PCM_MIXBUF_LEN) - // shouldn't happen - steps = PCM_MIXBUF_LEN - Pico_mcd->pcm_mixpos; + Pico_mcd->pcm_regs_dirty = 0; for (c = 0; c < 8; c++) { - if (!(Pico_mcd->pcm.enabled & (1 << c))) + ch = &Pico_mcd->pcm.ch[c]; + + if (!(enabled & (1 << c))) { + ch->addr = ch->regs[6] << (PCM_STEP_SHIFT + 8); continue; // channel disabled + } - ch = &Pico_mcd->pcm.ch[c]; addr = ch->addr; inc = *(unsigned short *)&ch->regs[2]; mul_l = ((int)ch->regs[0] * (ch->regs[1] & 0xf)) >> (5+1); diff --git a/pico/pico_int.h b/pico/pico_int.h index a33051cc..41dc59dc 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -447,7 +447,8 @@ typedef struct _scd scd; int pcm_mixbuf[PCM_MIXBUF_LEN * 2]; int pcm_mixpos; - int pcm_mixbuf_dirty; + char pcm_mixbuf_dirty; + char pcm_regs_dirty; } mcd_state; // XXX: this will need to be reworked for cart+cd support. -- 2.39.5