From 15b2efc81e4897618e5b024937b61cba26c0df80 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sun, 2 Dec 2018 10:02:59 +0900 Subject: scsp.cpp : Minor updates Code style fixes, Correct SSCTL, Initial RBL, Add notes, Cleanup unused / duplicates --- src/devices/sound/scsp.cpp | 1114 ++++++++++++++++++++--------------------- src/devices/sound/scsp.h | 1 - src/devices/sound/scspdsp.cpp | 8 +- 3 files changed, 547 insertions(+), 576 deletions(-) diff --git a/src/devices/sound/scsp.cpp b/src/devices/sound/scsp.cpp index bce6934a49c..01d214fca53 100644 --- a/src/devices/sound/scsp.cpp +++ b/src/devices/sound/scsp.cpp @@ -41,7 +41,7 @@ static constexpr int32_t clip18(int x) { return std::min(131071, std::max(-13107 #define SHIFT 12 #define LFO_SHIFT 8 -#define FIX(v) ((uint32_t) ((float) (1<udata.data[0x0]>>0x0)&0x1000) -#define KEYONB(slot) ((slot->udata.data[0x0]>>0x0)&0x0800) -#define SBCTL(slot) ((slot->udata.data[0x0]>>0x9)&0x0003) -#define SSCTL(slot) ((slot->udata.data[0x0]>>0x7)&0x0003) -#define LPCTL(slot) ((slot->udata.data[0x0]>>0x5)&0x0003) -#define PCM8B(slot) ((slot->udata.data[0x0]>>0x0)&0x0010) +#define KEYONEX(slot) ((slot->udata.data[0x0] >> 0x0) & 0x1000) +#define KEYONB(slot) ((slot->udata.data[0x0] >> 0x0) & 0x0800) +#define SBCTL(slot) ((slot->udata.data[0x0] >> 0x9) & 0x0003) +#define SSCTL(slot) ((slot->udata.data[0x0] >> 0x7) & 0x0003) +#define LPCTL(slot) ((slot->udata.data[0x0] >> 0x5) & 0x0003) +#define PCM8B(slot) ((slot->udata.data[0x0] >> 0x0) & 0x0010) -#define SA(slot) (((slot->udata.data[0x0]&0xF)<<16)|(slot->udata.data[0x1])) +#define SA(slot) (((slot->udata.data[0x0] & 0xF) << 16) | (slot->udata.data[0x1])) #define LSA(slot) (slot->udata.data[0x2]) #define LEA(slot) (slot->udata.data[0x3]) -#define D2R(slot) ((slot->udata.data[0x4]>>0xB)&0x001F) -#define D1R(slot) ((slot->udata.data[0x4]>>0x6)&0x001F) -#define EGHOLD(slot) ((slot->udata.data[0x4]>>0x0)&0x0020) -#define AR(slot) ((slot->udata.data[0x4]>>0x0)&0x001F) +#define D2R(slot) ((slot->udata.data[0x4] >> 0xB) & 0x001F) +#define D1R(slot) ((slot->udata.data[0x4] >> 0x6) & 0x001F) +#define EGHOLD(slot) ((slot->udata.data[0x4] >> 0x0) & 0x0020) +#define AR(slot) ((slot->udata.data[0x4] >> 0x0) & 0x001F) -#define LPSLNK(slot) ((slot->udata.data[0x5]>>0x0)&0x4000) -#define KRS(slot) ((slot->udata.data[0x5]>>0xA)&0x000F) -#define DL(slot) ((slot->udata.data[0x5]>>0x5)&0x001F) -#define RR(slot) ((slot->udata.data[0x5]>>0x0)&0x001F) +#define LPSLNK(slot) ((slot->udata.data[0x5] >> 0x0) & 0x4000) +#define KRS(slot) ((slot->udata.data[0x5] >> 0xA) & 0x000F) +#define DL(slot) ((slot->udata.data[0x5] >> 0x5) & 0x001F) +#define RR(slot) ((slot->udata.data[0x5] >> 0x0) & 0x001F) -#define STWINH(slot) ((slot->udata.data[0x6]>>0x0)&0x0200) -#define SDIR(slot) ((slot->udata.data[0x6]>>0x0)&0x0100) -#define TL(slot) ((slot->udata.data[0x6]>>0x0)&0x00FF) +#define STWINH(slot) ((slot->udata.data[0x6] >> 0x0) & 0x0200) +#define SDIR(slot) ((slot->udata.data[0x6] >> 0x0) & 0x0100) +#define TL(slot) ((slot->udata.data[0x6] >> 0x0) & 0x00FF) -#define MDL(slot) ((slot->udata.data[0x7]>>0xC)&0x000F) -#define MDXSL(slot) ((slot->udata.data[0x7]>>0x6)&0x003F) -#define MDYSL(slot) ((slot->udata.data[0x7]>>0x0)&0x003F) +#define MDL(slot) ((slot->udata.data[0x7] >> 0xC) & 0x000F) +#define MDXSL(slot) ((slot->udata.data[0x7] >> 0x6) & 0x003F) +#define MDYSL(slot) ((slot->udata.data[0x7] >> 0x0) & 0x003F) -#define OCT(slot) ((slot->udata.data[0x8]>>0xB)&0x000F) -#define FNS(slot) ((slot->udata.data[0x8]>>0x0)&0x03FF) +#define OCT(slot) ((slot->udata.data[0x8] >> 0xB) & 0x000F) +#define FNS(slot) ((slot->udata.data[0x8] >> 0x0) & 0x03FF) -#define LFORE(slot) ((slot->udata.data[0x9]>>0x0)&0x8000) -#define LFOF(slot) ((slot->udata.data[0x9]>>0xA)&0x001F) -#define PLFOWS(slot) ((slot->udata.data[0x9]>>0x8)&0x0003) -#define PLFOS(slot) ((slot->udata.data[0x9]>>0x5)&0x0007) -#define ALFOWS(slot) ((slot->udata.data[0x9]>>0x3)&0x0003) -#define ALFOS(slot) ((slot->udata.data[0x9]>>0x0)&0x0007) +#define LFORE(slot) ((slot->udata.data[0x9] >> 0x0) & 0x8000) +#define LFOF(slot) ((slot->udata.data[0x9] >> 0xA) & 0x001F) +#define PLFOWS(slot) ((slot->udata.data[0x9] >> 0x8) & 0x0003) +#define PLFOS(slot) ((slot->udata.data[0x9] >> 0x5) & 0x0007) +#define ALFOWS(slot) ((slot->udata.data[0x9] >> 0x3) & 0x0003) +#define ALFOS(slot) ((slot->udata.data[0x9] >> 0x0) & 0x0007) -#define ISEL(slot) ((slot->udata.data[0xA]>>0x3)&0x000F) -#define IMXL(slot) ((slot->udata.data[0xA]>>0x0)&0x0007) +#define ISEL(slot) ((slot->udata.data[0xA] >> 0x3) & 0x000F) +#define IMXL(slot) ((slot->udata.data[0xA] >> 0x0) & 0x0007) -#define DISDL(slot) ((slot->udata.data[0xB]>>0xD)&0x0007) -#define DIPAN(slot) ((slot->udata.data[0xB]>>0x8)&0x001F) -#define EFSDL(slot) ((slot->udata.data[0xB]>>0x5)&0x0007) -#define EFPAN(slot) ((slot->udata.data[0xB]>>0x0)&0x001F) +#define DISDL(slot) ((slot->udata.data[0xB] >> 0xD) & 0x0007) +#define DIPAN(slot) ((slot->udata.data[0xB] >> 0x8) & 0x001F) +#define EFSDL(slot) ((slot->udata.data[0xB] >> 0x5) & 0x0007) +#define EFPAN(slot) ((slot->udata.data[0xB] >> 0x0) & 0x001F) //Envelope times in ms -static const double ARTimes[64]={100000/*infinity*/,100000/*infinity*/,8100.0,6900.0,6000.0,4800.0,4000.0,3400.0,3000.0,2400.0,2000.0,1700.0,1500.0, +static const double ARTimes[64] = {100000/*infinity*/,100000/*infinity*/,8100.0,6900.0,6000.0,4800.0,4000.0,3400.0,3000.0,2400.0,2000.0,1700.0,1500.0, 1200.0,1000.0,860.0,760.0,600.0,500.0,430.0,380.0,300.0,250.0,220.0,190.0,150.0,130.0,110.0,95.0, 76.0,63.0,55.0,47.0,38.0,31.0,27.0,24.0,19.0,15.0,13.0,12.0,9.4,7.9,6.8,6.0,4.7,3.8,3.4,3.0,2.4, 2.0,1.8,1.6,1.3,1.1,0.93,0.85,0.65,0.53,0.44,0.40,0.35,0.0,0.0}; -static const double DRTimes[64]={100000/*infinity*/,100000/*infinity*/,118200.0,101300.0,88600.0,70900.0,59100.0,50700.0,44300.0,35500.0,29600.0,25300.0,22200.0,17700.0, +static const double DRTimes[64] = {100000/*infinity*/,100000/*infinity*/,118200.0,101300.0,88600.0,70900.0,59100.0,50700.0,44300.0,35500.0,29600.0,25300.0,22200.0,17700.0, 14800.0,12700.0,11100.0,8900.0,7400.0,6300.0,5500.0,4400.0,3700.0,3200.0,2800.0,2200.0,1800.0,1600.0,1400.0,1100.0, 920.0,790.0,690.0,550.0,460.0,390.0,340.0,270.0,230.0,200.0,170.0,140.0,110.0,98.0,85.0,68.0,57.0,49.0,43.0,34.0, 28.0,25.0,22.0,18.0,14.0,12.0,11.0,8.5,7.1,6.1,5.4,4.3,3.6,3.1}; -#define MEM4B() ((m_udata.data[0]>>0x0)&0x0200) -#define DAC18B() ((m_udata.data[0]>>0x0)&0x0100) -#define MVOL() ((m_udata.data[0]>>0x0)&0x000F) -#define RBL() ((m_udata.data[1]>>0x7)&0x0003) -#define RBP() ((m_udata.data[1]>>0x0)&0x003F) -#define MOFULL() ((m_udata.data[2]>>0x0)&0x1000) -#define MOEMPTY() ((m_udata.data[2]>>0x0)&0x0800) -#define MIOVF() ((m_udata.data[2]>>0x0)&0x0400) -#define MIFULL() ((m_udata.data[2]>>0x0)&0x0200) -#define MIEMPTY() ((m_udata.data[2]>>0x0)&0x0100) - -#define SCILV0() ((m_udata.data[0x24/2]>>0x0)&0xff) -#define SCILV1() ((m_udata.data[0x26/2]>>0x0)&0xff) -#define SCILV2() ((m_udata.data[0x28/2]>>0x0)&0xff) +#define MEM4B() ((m_udata.data[0] >> 0x0) & 0x0200) +#define DAC18B() ((m_udata.data[0] >> 0x0) & 0x0100) +#define MVOL() ((m_udata.data[0] >> 0x0) & 0x000F) +#define RBL() ((m_udata.data[1] >> 0x7) & 0x0003) +#define RBP() ((m_udata.data[1] >> 0x0) & 0x003F) +#define MOFULL() ((m_udata.data[2] >> 0x0) & 0x1000) +#define MOEMPTY() ((m_udata.data[2] >> 0x0) & 0x0800) +#define MIOVF() ((m_udata.data[2] >> 0x0) & 0x0400) +#define MIFULL() ((m_udata.data[2] >> 0x0) & 0x0200) +#define MIEMPTY() ((m_udata.data[2] >> 0x0) & 0x0100) + +#define SCILV0() ((m_udata.data[0x24/2] >> 0x0) & 0xff) +#define SCILV1() ((m_udata.data[0x26/2] >> 0x0) & 0xff) +#define SCILV2() ((m_udata.data[0x28/2] >> 0x0) & 0xff) #define SCIEX0 0 #define SCIEX1 1 @@ -139,11 +139,11 @@ static const double DRTimes[64]={100000/*infinity*/,100000/*infinity*/,118200.0, #define USEDSP /* TODO */ -//#define dma_transfer_end ((scsp_regs[0x24/2] & 0x10)>>4)|(((scsp_regs[0x26/2] & 0x10)>>4)<<1)|(((scsp_regs[0x28/2] & 0x10)>>4)<<2) +//#define dma_transfer_end ((scsp_regs[0x24/2] & 0x10) >> 4) | (((scsp_regs[0x26/2] & 0x10) >> 4) << 1) | (((scsp_regs[0x28/2] & 0x10) >> 4) << 2) -static const float SDLT[8]={-1000000.0f,-36.0f,-30.0f,-24.0f,-18.0f,-12.0f,-6.0f,0.0f}; +static const float SDLT[8] = {-1000000.0f,-36.0f,-30.0f,-24.0f,-18.0f,-12.0f,-6.0f,0.0f}; -DEFINE_DEVICE_TYPE(SCSP, scsp_device, "scsp", "YMF292-F SCSP") +DEFINE_DEVICE_TYPE(SCSP, scsp_device, "scsp", "Yamaha YMF292-F SCSP") scsp_device::scsp_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, SCSP, tag, owner, clock), @@ -298,8 +298,8 @@ void scsp_device::device_post_load() for (int slot = 0; slot < 32; slot++) Compute_LFO(&m_Slots[slot]); - m_stream->set_output_gain(0,MVOL() / 15.0); - m_stream->set_output_gain(1,MVOL() / 15.0); + m_stream->set_output_gain(0, MVOL() / 15.0); + m_stream->set_output_gain(1, MVOL() / 15.0); } //------------------------------------------------- @@ -331,50 +331,50 @@ void scsp_device::sound_stream_update(sound_stream &stream, stream_sample_t **in DoMasterSamples(samples); } -unsigned char scsp_device::DecodeSCI(unsigned char irq) +uint8_t scsp_device::DecodeSCI(uint8_t irq) { - unsigned char SCI=0; - unsigned char v; - v=(SCILV0()&(1<>8; + m_udata.data[0x20/2] |= 0x40; + m_udata.data[0x18/2] &= 0xff00; + m_udata.data[0x18/2] |= m_TimCnt[0] >> 8; CheckPendingIRQ(); MainCheckPendingIRQ(0x40); @@ -430,9 +430,9 @@ TIMER_CALLBACK_MEMBER( scsp_device::timerA_cb ) TIMER_CALLBACK_MEMBER( scsp_device::timerB_cb ) { m_TimCnt[1] = 0xFFFF; - m_udata.data[0x20/2]|=0x80; - m_udata.data[0x1a/2]&=0xff00; - m_udata.data[0x1a/2]|=m_TimCnt[1]>>8; + m_udata.data[0x20/2] |= 0x80; + m_udata.data[0x1a/2] &= 0xff00; + m_udata.data[0x1a/2] |= m_TimCnt[1] >> 8; CheckPendingIRQ(); } @@ -440,116 +440,104 @@ TIMER_CALLBACK_MEMBER( scsp_device::timerB_cb ) TIMER_CALLBACK_MEMBER( scsp_device::timerC_cb ) { m_TimCnt[2] = 0xFFFF; - m_udata.data[0x20/2]|=0x100; - m_udata.data[0x1c/2]&=0xff00; - m_udata.data[0x1c/2]|=m_TimCnt[2]>>8; + m_udata.data[0x20/2] |= 0x100; + m_udata.data[0x1c/2] &= 0xff00; + m_udata.data[0x1c/2] |= m_TimCnt[2] >> 8; CheckPendingIRQ(); } int scsp_device::Get_AR(int base, int R) { - int Rate=base+(R<<1); - if(Rate>63) Rate=63; - if(Rate<0) Rate=0; - return m_ARTABLE[Rate]; + int Rate = base + (R << 1); + return m_ARTABLE[std::min(63, std::max(0, Rate))]; } int scsp_device::Get_DR(int base, int R) { - int Rate=base+(R<<1); - if(Rate>63) Rate=63; - if(Rate<0) Rate=0; - return m_DRTABLE[Rate]; -} - -int scsp_device::Get_RR(int base, int R) -{ - int Rate=base+(R<<1); - if(Rate>63) Rate=63; - if(Rate<0) Rate=0; - return m_DRTABLE[Rate]; + int Rate = base + (R << 1); + return m_DRTABLE[std::min(63, std::max(0, Rate))]; } void scsp_device::Compute_EG(SCSP_SLOT *slot) { - int octave=(OCT(slot)^8)-8; + int octave = (OCT(slot) ^ 8) - 8; int rate; - if(KRS(slot)!=0xf) - rate=octave+2*KRS(slot)+((FNS(slot)>>9)&1); + if (KRS(slot) != 0xf) + rate = octave + 2 * KRS(slot) + ((FNS(slot) >> 9) & 1); else - rate=0; //rate=((FNS(slot)>>9)&1); - - slot->EG.volume=0x17F<EG.AR=Get_AR(rate,AR(slot)); - slot->EG.D1R=Get_DR(rate,D1R(slot)); - slot->EG.D2R=Get_DR(rate,D2R(slot)); - slot->EG.RR=Get_RR(rate,RR(slot)); - slot->EG.DL=0x1f-DL(slot); - slot->EG.EGHOLD=EGHOLD(slot); + rate = 0; //rate = ((FNS(slot) >> 9) & 1); + + slot->EG.volume = 0x17F<EG.AR = Get_AR(rate,AR(slot)); + slot->EG.D1R = Get_DR(rate,D1R(slot)); + slot->EG.D2R = Get_DR(rate,D2R(slot)); + slot->EG.RR = Get_DR(rate,RR(slot)); + slot->EG.DL = 0x1f - DL(slot); + slot->EG.EGHOLD = EGHOLD(slot); } int scsp_device::EG_Update(SCSP_SLOT *slot) { - switch(slot->EG.state) + switch (slot->EG.state) { case SCSP_ATTACK: - slot->EG.volume+=slot->EG.AR; - if(slot->EG.volume>=(0x3ff<EG.volume += slot->EG.AR; + if (slot->EG.volume >= (0x3ff<EG.state=SCSP_DECAY1; - if(slot->EG.D1R>=(1024<EG.state=SCSP_DECAY2; + slot->EG.state = SCSP_DECAY1; + if (slot->EG.D1R >= (1024 << EG_SHIFT)) //Skip SCSP_DECAY1, go directly to SCSP_DECAY2 + slot->EG.state = SCSP_DECAY2; } - slot->EG.volume=0x3ff<EG.volume=0x3ff << EG_SHIFT; } - if(slot->EG.EGHOLD) - return 0x3ff<<(SHIFT-10); + if (slot->EG.EGHOLD) + return 0x3ff << (SHIFT - 10); break; case SCSP_DECAY1: - slot->EG.volume-=slot->EG.D1R; - if(slot->EG.volume<=0) - slot->EG.volume=0; - if(slot->EG.volume>>(EG_SHIFT+5)<=slot->EG.DL) - slot->EG.state=SCSP_DECAY2; + slot->EG.volume -= slot->EG.D1R; + if (slot->EG.volume <= 0) + slot->EG.volume = 0; + if (slot->EG.volume >> (EG_SHIFT + 5) <= slot->EG.DL) + slot->EG.state = SCSP_DECAY2; break; case SCSP_DECAY2: - if(D2R(slot)==0) - return (slot->EG.volume>>EG_SHIFT)<<(SHIFT-10); - slot->EG.volume-=slot->EG.D2R; - if(slot->EG.volume<=0) - slot->EG.volume=0; + if (D2R(slot) == 0) + return (slot->EG.volume >> EG_SHIFT) << (SHIFT - 10); + slot->EG.volume -= slot->EG.D2R; + if (slot->EG.volume <= 0) + slot->EG.volume = 0; break; case SCSP_RELEASE: - slot->EG.volume-=slot->EG.RR; - if(slot->EG.volume<=0) + slot->EG.volume -= slot->EG.RR; + if (slot->EG.volume <= 0) { - slot->EG.volume=0; - StopSlot(slot,0); - //slot->EG.volume=0x17F<EG.state=SCSP_ATTACK; + slot->EG.volume = 0; + StopSlot(slot, 0); + //slot->EG.volume = 0x17F << EG_SHIFT; + //slot->EG.state = SCSP_ATTACK; } break; default: - return 1<EG.volume>>EG_SHIFT)<<(SHIFT-10); + return (slot->EG.volume >> EG_SHIFT) << (SHIFT - 10); } uint32_t scsp_device::Step(SCSP_SLOT *slot) { - int octave=(OCT(slot)^8)-8+SHIFT-10; - uint32_t Fn=FNS(slot)+(1 << 10); + int octave = (OCT(slot) ^ 8) - 8 + SHIFT - 10; + uint32_t Fn = FNS(slot) + (1 << 10); if (octave >= 0) { - Fn<<=octave; + Fn <<= octave; } else { - Fn>>=-octave; + Fn >>= -octave; } return Fn; @@ -558,23 +546,23 @@ uint32_t scsp_device::Step(SCSP_SLOT *slot) void scsp_device::Compute_LFO(SCSP_SLOT *slot) { - if(PLFOS(slot)!=0) - LFO_ComputeStep(&(slot->PLFO),LFOF(slot),PLFOWS(slot),PLFOS(slot),0); - if(ALFOS(slot)!=0) - LFO_ComputeStep(&(slot->ALFO),LFOF(slot),ALFOWS(slot),ALFOS(slot),1); + if (PLFOS(slot) != 0) + LFO_ComputeStep(&(slot->PLFO), LFOF(slot), PLFOWS(slot), PLFOS(slot), 0); + if (ALFOS(slot) != 0) + LFO_ComputeStep(&(slot->ALFO), LFOF(slot), ALFOWS(slot), ALFOS(slot), 1); } void scsp_device::StartSlot(SCSP_SLOT *slot) { - slot->active=1; - slot->cur_addr=0; - slot->nxt_addr=1<step=Step(slot); + slot->active = 1; + slot->cur_addr = 0; + slot->nxt_addr = 1 << SHIFT; + slot->step = Step(slot); Compute_EG(slot); - slot->EG.state=SCSP_ATTACK; - slot->EG.volume=0x17F<Prev=0; - slot->Backwards=0; + slot->EG.state = SCSP_ATTACK; + slot->EG.volume = 0x17F << EG_SHIFT; + slot->Prev = 0; + slot->Backwards = 0; Compute_LFO(slot); @@ -583,19 +571,17 @@ void scsp_device::StartSlot(SCSP_SLOT *slot) void scsp_device::StopSlot(SCSP_SLOT *slot,int keyoff) { - if(keyoff /*&& slot->EG.state!=SCSP_RELEASE*/) + if (keyoff /*&& slot->EG.state!=SCSP_RELEASE*/) { - slot->EG.state=SCSP_RELEASE; + slot->EG.state = SCSP_RELEASE; } else { - slot->active=0; + slot->active = 0; } - slot->udata.data[0]&=~0x800; + slot->udata.data[0] &= ~0x800; } -#define log_base_2(n) (log((double)(n))/log(2.0)) - void scsp_device::init() { int i; @@ -621,91 +607,91 @@ void scsp_device::init() m_timerB = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerB_cb), this)); m_timerC = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(scsp_device::timerC_cb), this)); - for(i=0;i<0x400;++i) + for (i = 0; i < 0x400; ++i) { - float envDB=((float)(3*(i-0x3ff)))/32.0f; - float scale=(float)(1<>0x0)&0xff; - int iPAN=(i>>0x8)&0x1f; - int iSDL=(i>>0xD)&0x07; + int iTL = (i >> 0x0) & 0xff; + int iPAN = (i >> 0x8) & 0x1f; + int iSDL = (i >> 0xD) & 0x07; float TL; - float SegaDB=0.0f; + float SegaDB = 0.0f; float fSDL; float PAN; float LPAN,RPAN; - if(iTL&0x01) SegaDB-=0.4f; - if(iTL&0x02) SegaDB-=0.8f; - if(iTL&0x04) SegaDB-=1.5f; - if(iTL&0x08) SegaDB-=3.0f; - if(iTL&0x10) SegaDB-=6.0f; - if(iTL&0x20) SegaDB-=12.0f; - if(iTL&0x40) SegaDB-=24.0f; - if(iTL&0x80) SegaDB-=48.0f; + if (iTL & 0x01) SegaDB -= 0.4f; + if (iTL & 0x02) SegaDB -= 0.8f; + if (iTL & 0x04) SegaDB -= 1.5f; + if (iTL & 0x08) SegaDB -= 3.0f; + if (iTL & 0x10) SegaDB -= 6.0f; + if (iTL & 0x20) SegaDB -= 12.0f; + if (iTL & 0x40) SegaDB -= 24.0f; + if (iTL & 0x80) SegaDB -= 48.0f; - TL=powf(10.0f,SegaDB/20.0f); + TL=powf(10.0f, SegaDB / 20.0f); SegaDB=0; - if(iPAN&0x1) SegaDB-=3.0f; - if(iPAN&0x2) SegaDB-=6.0f; - if(iPAN&0x4) SegaDB-=12.0f; - if(iPAN&0x8) SegaDB-=24.0f; + if (iPAN & 0x1) SegaDB -= 3.0f; + if (iPAN & 0x2) SegaDB -= 6.0f; + if (iPAN & 0x4) SegaDB -= 12.0f; + if (iPAN & 0x8) SegaDB -= 24.0f; - if((iPAN&0xf)==0xf) PAN=0.0; - else PAN=powf(10.0f,SegaDB/20.0f); + if ((iPAN & 0xf) == 0xf) PAN = 0.0; + else PAN=powf(10.0f, SegaDB / 20.0f); - if(iPAN<0x10) + if (iPAN < 0x10) { - LPAN=PAN; - RPAN=1.0; + LPAN = PAN; + RPAN = 1.0; } else { - RPAN=PAN; - LPAN=1.0; + RPAN = PAN; + LPAN = 1.0; } - if(iSDL) - fSDL=powf(10.0f,(SDLT[iSDL])/20.0f); + if (iSDL) + fSDL = powf(10.0f, (SDLT[iSDL]) / 20.0f); else - fSDL=0.0; + fSDL = 0.0; - m_LPANTABLE[i]=FIX((4.0f*LPAN*TL*fSDL)); - m_RPANTABLE[i]=FIX((4.0f*RPAN*TL*fSDL)); + m_LPANTABLE[i] = FIX((4.0f * LPAN * TL * fSDL)); + m_RPANTABLE[i] = FIX((4.0f * RPAN * TL * fSDL)); } - m_ARTABLE[0]=m_DRTABLE[0]=0; //Infinite time - m_ARTABLE[1]=m_DRTABLE[1]=0; //Infinite time - for(i=2;i<64;++i) + m_ARTABLE[0] = m_DRTABLE[0] = 0; //Infinite time + m_ARTABLE[1] = m_DRTABLE[1] = 0; //Infinite time + for (i = 2; i < 64; ++i) { - double t,step,scale; - t=ARTimes[i]; //In ms - if(t!=0.0) + double step, scale; + double t = ARTimes[i]; //In ms + if (t != 0.0) { - step=(1023*1000.0) / (44100.0*t); - scale=(double) (1<EG.state==SCSP_RELEASE/*&& !s2->active*/) + if (KEYONB(s2) && s2->EG.state == SCSP_RELEASE/*&& !s2->active*/) { StartSlot(s2); } - if(!KEYONB(s2) /*&& s2->active*/) + if (!KEYONB(s2) /*&& s2->active*/) { - StopSlot(s2,1); + StopSlot(s2, 1); } } } - slot->udata.data[0]&=~0x1000; + slot->udata.data[0] &= ~0x1000; } break; case 0x10: case 0x11: - slot->step=Step(slot); + slot->step = Step(slot); break; case 0xA: case 0xB: - slot->EG.RR=Get_RR(0,RR(slot)); - slot->EG.DL=0x1f-DL(slot); + slot->EG.RR = Get_DR(0, RR(slot)); + slot->EG.DL = 0x1f - DL(slot); break; case 0x12: case 0x13: @@ -761,30 +746,22 @@ void scsp_device::UpdateSlotReg(int s,int r) void scsp_device::UpdateReg(int reg) { - switch(reg&0x3f) + switch (reg & 0x3f) { case 0x0: - m_stream->set_output_gain(0,MVOL() / 15.0); - m_stream->set_output_gain(1,MVOL() / 15.0); + m_stream->set_output_gain(0, MVOL() / 15.0); + m_stream->set_output_gain(1, MVOL() / 15.0); break; case 0x2: case 0x3: { - unsigned int v=RBL(); - m_DSP.RBP=RBP(); - if(v==0) - m_DSP.RBL=8*1024; - else if(v==1) - m_DSP.RBL=16*1024; - if(v==2) - m_DSP.RBL=32*1024; - if(v==3) - m_DSP.RBL=64*1024; + m_DSP.RBL = (8 * 1024) << RBL(); // 8 / 16 / 32 / 64 kwords + m_DSP.RBP = RBP(); } break; case 0x6: case 0x7: - midi_in(m_udata.data[0x6/2]&0xff); + midi_in(m_udata.data[0x6/2] & 0xff); break; case 8: case 9: @@ -805,21 +782,19 @@ void scsp_device::UpdateReg(int reg) m_dma.dtlg = (m_udata.data[0x16/2] & 0x0ffe); m_dma.ddir = (m_udata.data[0x16/2] & 0x2000) >> 13; m_dma.dgate = (m_udata.data[0x16/2] & 0x4000) >> 14; - if(m_udata.data[0x16/2] & 0x1000) // dexe + if (m_udata.data[0x16/2] & 0x1000) // dexe exec_dma(); break; case 0x18: case 0x19: - if(m_Master) + if (m_Master) { - uint32_t time; - - m_TimPris[0]=1<<((m_udata.data[0x18/2]>>8)&0x7); - m_TimCnt[0]=(m_udata.data[0x18/2]&0xff)<<8; + m_TimPris[0] = 1 << ((m_udata.data[0x18/2] >> 8) & 0x7); + m_TimCnt[0] = (m_udata.data[0x18/2] & 0xff) << 8; - if ((m_udata.data[0x18/2]&0xff) != 255) + if ((m_udata.data[0x18/2] & 0xff) != 255) { - time = (clock() / m_TimPris[0]) / (255-(m_udata.data[0x18/2]&0xff)); + uint32_t time = (clock() / m_TimPris[0]) / (255 - (m_udata.data[0x18/2] & 0xff)); if (time) { m_timerA->adjust(attotime::from_ticks(512, time)); @@ -829,16 +804,14 @@ void scsp_device::UpdateReg(int reg) break; case 0x1a: case 0x1b: - if(m_Master) + if (m_Master) { - uint32_t time; - - m_TimPris[1]=1<<((m_udata.data[0x1A/2]>>8)&0x7); - m_TimCnt[1]=(m_udata.data[0x1A/2]&0xff)<<8; + m_TimPris[1] = 1 << ((m_udata.data[0x1A/2] >> 8) & 0x7); + m_TimCnt[1] = (m_udata.data[0x1A/2] & 0xff) << 8; - if ((m_udata.data[0x1A/2]&0xff) != 255) + if ((m_udata.data[0x1A/2] & 0xff) != 255) { - time = (clock() / m_TimPris[1]) / (255-(m_udata.data[0x1A/2]&0xff)); + uint32_t time = (clock() / m_TimPris[1]) / (255 - (m_udata.data[0x1A/2] & 0xff)); if (time) { m_timerB->adjust(attotime::from_ticks(512, time)); @@ -848,16 +821,14 @@ void scsp_device::UpdateReg(int reg) break; case 0x1C: case 0x1D: - if(m_Master) + if (m_Master) { - uint32_t time; + m_TimPris[2] = 1 << ((m_udata.data[0x1C/2] >> 8) & 0x7); + m_TimCnt[2] = (m_udata.data[0x1C/2] & 0xff) << 8; - m_TimPris[2]=1<<((m_udata.data[0x1C/2]>>8)&0x7); - m_TimCnt[2]=(m_udata.data[0x1C/2]&0xff)<<8; - - if ((m_udata.data[0x1C/2]&0xff) != 255) + if ((m_udata.data[0x1C/2] & 0xff) != 255) { - time = (clock() / m_TimPris[2]) / (255-(m_udata.data[0x1C/2]&0xff)); + uint32_t time = (clock() / m_TimPris[2]) / (255 - (m_udata.data[0x1C/2] & 0xff)); if (time) { m_timerC->adjust(attotime::from_ticks(512, time)); @@ -867,28 +838,28 @@ void scsp_device::UpdateReg(int reg) break; case 0x1e: // SCIEB case 0x1f: - if(m_Master) + if (m_Master) { CheckPendingIRQ(); - if(m_udata.data[0x1e/2] & 0x610) + if (m_udata.data[0x1e/2] & 0x610) popmessage("SCSP SCIEB enabled %04x, contact MAMEdev",m_udata.data[0x1e/2]); } break; case 0x20: // SCIPD case 0x21: - if(m_Master) + if (m_Master) { - if(m_udata.data[0x1e/2] & m_udata.data[0x20/2] & 0x20) + if (m_udata.data[0x1e/2] & m_udata.data[0x20/2] & 0x20) popmessage("SCSP SCIPD write %04x, contact MAMEdev",m_udata.data[0x20/2]); } break; case 0x22: //SCIRE case 0x23: - if(m_Master) + if (m_Master) { - m_udata.data[0x20/2]&=~m_udata.data[0x22/2]; + m_udata.data[0x20/2] &= ~m_udata.data[0x22/2]; ResetInterrupts(); // behavior from real hardware: if you SCIRE a timer that's expired, @@ -913,11 +884,11 @@ void scsp_device::UpdateReg(int reg) case 0x27: case 0x28: case 0x29: - if(m_Master) + if (m_Master) { - m_IrqTimA=DecodeSCI(SCITMA); - m_IrqTimBC=DecodeSCI(SCITMB); - m_IrqMidi=DecodeSCI(SCIMID); + m_IrqTimA = DecodeSCI(SCITMA); + m_IrqTimBC = DecodeSCI(SCITMB); + m_IrqMidi = DecodeSCI(SCIMID); } break; case 0x2a: @@ -925,12 +896,12 @@ void scsp_device::UpdateReg(int reg) m_mcieb = m_udata.data[0x2a/2]; MainCheckPendingIRQ(0); - if(m_mcieb & ~0x60) + if (m_mcieb & ~0x60) popmessage("SCSP MCIEB enabled %04x, contact MAMEdev",m_mcieb); break; case 0x2c: case 0x2d: - if(m_udata.data[0x2c/2] & 0x20) + if (m_udata.data[0x2c/2] & 0x20) MainCheckPendingIRQ(0x20); break; case 0x2e: @@ -948,22 +919,22 @@ void scsp_device::UpdateSlotRegR(int slot,int reg) void scsp_device::UpdateRegR(int reg) { - switch(reg&0x3f) + switch (reg & 0x3f) { case 4: case 5: { - unsigned short v=m_udata.data[0x5/2]; - v&=0xff00; - v|=m_MidiStack[m_MidiR]; + uint16_t v = m_udata.data[0x4/2]; + v &= 0xff00; + v |= m_MidiStack[m_MidiR]; m_irq_cb(m_IrqMidi, CLEAR_LINE); // cancel the IRQ logerror("Read %x from SCSP MIDI\n", v); - if(m_MidiR!=m_MidiW) + if (m_MidiR != m_MidiW) { ++m_MidiR; - m_MidiR&=31; + m_MidiR &= 31; } - m_udata.data[0x5/2]=v; + m_udata.data[0x4/2] = v; } break; case 8: @@ -971,11 +942,11 @@ void scsp_device::UpdateRegR(int reg) { // MSLC | CA |SGC|EG // f e d c b a 9 8 7 6 5 4 3 2 1 0 - unsigned char MSLC=(m_udata.data[0x8/2]>>11)&0x1f; - SCSP_SLOT *slot=m_Slots + MSLC; - unsigned int SGC = (slot->EG.state) & 3; - unsigned int CA = (slot->cur_addr>>(SHIFT+12)) & 0xf; - unsigned int EG = (0x1f - (slot->EG.volume>>(EG_SHIFT+5))) & 0x1f; + uint8_t MSLC = (m_udata.data[0x8/2] >> 11) & 0x1f; + SCSP_SLOT *slot = m_Slots + MSLC; + uint32_t SGC = (slot->EG.state) & 3; + uint32_t CA = (slot->cur_addr >> (SHIFT + 12)) & 0xf; + uint32_t EG = (0x1f - (slot->EG.volume >> (EG_SHIFT + 5))) & 0x1f; /* note: according to the manual MSLC is write only, CA, SGC and EG read only. */ m_udata.data[0x8/2] = /*(MSLC << 11) |*/ (CA << 7) | (SGC << 5) | EG; } @@ -1005,40 +976,40 @@ void scsp_device::UpdateRegR(int reg) } } -void scsp_device::w16(unsigned int addr,unsigned short val) +void scsp_device::w16(uint32_t addr, uint16_t val) { - addr&=0xffff; - if(addr<0x400) + addr &= 0xffff; + if (addr < 0x400) { - int slot=addr/0x20; - addr&=0x1f; - *((unsigned short *) (m_Slots[slot].udata.datab+(addr))) = val; - UpdateSlotReg(slot,addr&0x1f); + int slot = addr / 0x20; + addr &= 0x1f; + *((uint16_t *) (m_Slots[slot].udata.datab + (addr))) = val; + UpdateSlotReg(slot, addr & 0x1f); } - else if(addr<0x600) + else if (addr < 0x600) { if (addr < 0x430) { - *((unsigned short *) (m_udata.datab+((addr&0x3f)))) = val; - UpdateReg(addr&0x3f); + *((uint16_t *) (m_udata.datab + ((addr & 0x3f)))) = val; + UpdateReg(addr & 0x3f); } } - else if(addr<0x700) - m_RINGBUF[(addr-0x600)/2]=val; + else if (addr < 0x700) + m_RINGBUF[(addr - 0x600)/2] = val; else { //DSP - if(addr<0x780) //COEF - *((unsigned short *) (m_DSP.COEF+(addr-0x700)/2))=val; - else if(addr<0x7c0) - *((unsigned short *) (m_DSP.MADRS+(addr-0x780)/2))=val; - else if(addr<0x800) // MADRS is mirrored twice - *((unsigned short *) (m_DSP.MADRS+(addr-0x7c0)/2))=val; - else if(addr<0xC00) + if (addr < 0x780) //COEF + *((uint16_t *) (m_DSP.COEF + (addr - 0x700) / 2)) = val; + else if (addr < 0x7c0) + *((uint16_t *) (m_DSP.MADRS + (addr - 0x780) / 2)) = val; + else if (addr < 0x800) // MADRS is mirrored twice + *((uint16_t *) (m_DSP.MADRS + (addr - 0x7c0) / 2)) = val; + else if (addr < 0xC00) { - *((unsigned short *) (m_DSP.MPRO+(addr-0x800)/2))=val; + *((uint16_t *) (m_DSP.MPRO + (addr - 0x800) / 2)) = val; - if(addr==0xBF0) + if (addr == 0xBF0) { m_DSP.Start(); } @@ -1046,61 +1017,61 @@ void scsp_device::w16(unsigned int addr,unsigned short val) } } -unsigned short scsp_device::r16(unsigned int addr) +uint16_t scsp_device::r16(uint32_t addr) { - unsigned short v=0; - addr&=0xffff; - if(addr<0x400) + uint16_t v = 0; + addr &= 0xffff; + if (addr < 0x400) { - int slot=addr/0x20; - addr&=0x1f; - UpdateSlotRegR(slot,addr&0x1f); - v=*((unsigned short *) (m_Slots[slot].udata.datab+(addr))); + int slot = addr / 0x20; + addr &= 0x1f; + UpdateSlotRegR(slot, addr & 0x1f); + v = *((uint16_t *) (m_Slots[slot].udata.datab + (addr))); } - else if(addr<0x600) + else if (addr < 0x600) { if (addr < 0x430) { - UpdateRegR(addr&0x3f); - v= *((unsigned short *) (m_udata.datab+((addr&0x3f)))); + UpdateRegR(addr & 0x3f); + v = *((uint16_t *) (m_udata.datab + ((addr & 0x3f)))); } } - else if(addr<0x700) - v=m_RINGBUF[(addr-0x600)/2]; + else if (addr < 0x700) + v = m_RINGBUF[(addr-0x600)/2]; else { //DSP - if(addr<0x780) //COEF - v= *((unsigned short *) (m_DSP.COEF+(addr-0x700)/2)); - else if(addr<0x7c0) - v= *((unsigned short *) (m_DSP.MADRS+(addr-0x780)/2)); - else if(addr<0x800) - v= *((unsigned short *) (m_DSP.MADRS+(addr-0x7c0)/2)); - else if(addr<0xC00) - v= *((unsigned short *) (m_DSP.MPRO+(addr-0x800)/2)); - else if(addr<0xE00) + if (addr < 0x780) //COEF + v= *((uint16_t *) (m_DSP.COEF + (addr - 0x700) / 2)); + else if (addr < 0x7c0) + v= *((uint16_t *) (m_DSP.MADRS + (addr - 0x780) / 2)); + else if (addr < 0x800) + v= *((uint16_t *) (m_DSP.MADRS + (addr - 0x7c0) / 2)); + else if (addr < 0xC00) + v= *((uint16_t *) (m_DSP.MPRO + (addr - 0x800) / 2)); + else if (addr < 0xE00) { - if(addr & 2) - v= m_DSP.TEMP[(addr >> 2) & 0x7f] & 0xffff; + if (addr & 2) + v = m_DSP.TEMP[(addr >> 2) & 0x7f] & 0xffff; else - v= m_DSP.TEMP[(addr >> 2) & 0x7f] >> 16; + v = m_DSP.TEMP[(addr >> 2) & 0x7f] >> 16; } - else if(addr<0xE80) + else if (addr < 0xE80) { - if(addr & 2) - v= m_DSP.MEMS[(addr >> 2) & 0x1f] & 0xffff; + if (addr & 2) + v = m_DSP.MEMS[(addr >> 2) & 0x1f] & 0xffff; else - v= m_DSP.MEMS[(addr >> 2) & 0x1f] >> 16; + v = m_DSP.MEMS[(addr >> 2) & 0x1f] >> 16; } - else if(addr<0xEC0) + else if (addr < 0xEC0) { - if(addr & 2) - v= m_DSP.MIXS[(addr >> 2) & 0xf] & 0xffff; + if (addr & 2) + v = m_DSP.MIXS[(addr >> 2) & 0xf] & 0xffff; else - v= m_DSP.MIXS[(addr >> 2) & 0xf] >> 16; + v = m_DSP.MIXS[(addr >> 2) & 0xf] >> 16; } - else if(addr<0xEE0) - v= *((unsigned short *) (m_DSP.EFREG+(addr-0xec0)/2)); + else if (addr < 0xEE0) + v = *((uint16_t *) (m_DSP.EFREG + (addr - 0xec0) / 2)); else { /**! @@ -1139,169 +1110,177 @@ unsigned short scsp_device::r16(unsigned int addr) 004CB0: 4CDF 0002 movem.l (A7)+, D1 004CB4: 4E75 rts */ - logerror("SCSP: Reading from EXTS register %08x\n",addr); - if(addr<0xEE4) - v = *((unsigned short *) (m_DSP.EXTS+(addr-0xee0)/2)); + logerror("SCSP: Reading from EXTS register %08x\n", addr); + if (addr < 0xEE4) + v = *((uint16_t *) (m_DSP.EXTS + (addr - 0xee0) / 2)); } } return v; } -#define REVSIGN(v) ((~v)+1) - inline int32_t scsp_device::UpdateSlot(SCSP_SLOT *slot) { + if (SSCTL(slot) == 3) // manual says cannot be used + { + logerror("SCSP: Invaild SSCTL setting at slot %02x\n", slot->slot); + return 0; + } + int32_t sample; - int step=slot->step; - uint32_t addr1,addr2,addr_select; // current and next sample addresses + int step = slot->step; + uint32_t addr1, addr2, addr_select; // current and next sample addresses uint32_t *addr[2] = {&addr1, &addr2}; // used for linear interpolation uint32_t *slot_addr[2] = {&(slot->cur_addr), &(slot->nxt_addr)}; // - if(SSCTL(slot)!=0) //no FM or noise yet - return 0; - - if(PLFOS(slot)!=0) + if (PLFOS(slot) != 0) { - step=step*PLFO_Step(&(slot->PLFO)); - step>>=SHIFT; + step = step * PLFO_Step(&(slot->PLFO)); + step >>= SHIFT; } - if(PCM8B(slot)) + if (PCM8B(slot)) { - addr1=slot->cur_addr>>SHIFT; - addr2=slot->nxt_addr>>SHIFT; + addr1 = slot->cur_addr >> SHIFT; + addr2 = slot->nxt_addr >> SHIFT; } else { - addr1=(slot->cur_addr>>(SHIFT-1)) & ~1; - addr2=(slot->nxt_addr>>(SHIFT-1)) & ~1; + addr1 = (slot->cur_addr >> (SHIFT - 1)) & ~1; + addr2 = (slot->nxt_addr >> (SHIFT - 1)) & ~1; } - if(MDL(slot)!=0 || MDXSL(slot)!=0 || MDYSL(slot)!=0) + if (MDL(slot) != 0 || MDXSL(slot) != 0 || MDYSL(slot) != 0) { - int32_t smp=(m_RINGBUF[(m_BUFPTR+MDXSL(slot))&63]+m_RINGBUF[(m_BUFPTR+MDYSL(slot))&63])/2; + int32_t smp = (m_RINGBUF[(m_BUFPTR + MDXSL(slot)) & 63] + m_RINGBUF[(m_BUFPTR + MDYSL(slot)) & 63]) / 2; - smp<<=0xA; // associate cycle with 1024 - smp>>=0x1A-MDL(slot); // ex. for MDL=0xF, sample range corresponds to +/- 64 pi (32=2^5 cycles) so shift by 11 (16-5 == 0x1A-0xF) - if(!PCM8B(slot)) smp<<=1; + smp <<= 0xA; // associate cycle with 1024 + smp >>= 0x1A - MDL(slot); // ex. for MDL=0xF, sample range corresponds to +/- 64 pi (32=2^5 cycles) so shift by 11 (16-5 == 0x1A-0xF) + if (!PCM8B(slot)) smp <<= 1; - addr1+=smp; addr2+=smp; + addr1 += smp; addr2 += smp; } - if(PCM8B(slot)) //8 bit signed + if (SSCTL(slot) == 0) // External DRAM data { - int8_t p1=read_byte(SA(slot)+addr1); - int8_t p2=read_byte(SA(slot)+addr2); - int32_t s; - int32_t fpart=slot->cur_addr&((1<>SHIFT); - } - else //16 bit signed (endianness?) - { - int16_t p1=read_word(SA(slot)+addr1); - int16_t p2=read_word(SA(slot)+addr2); - int32_t s; - int32_t fpart=slot->cur_addr&((1<>SHIFT); + if (PCM8B(slot)) //8 bit signed + { + int8_t p1 = read_byte(SA(slot) + addr1); + int8_t p2 = read_byte(SA(slot) + addr2); + int32_t s; + int32_t fpart=slot->cur_addr & ((1 << SHIFT) - 1); + s = (int) (p1 << 8) * ((1 << SHIFT) - fpart) + (int) (p2 << 8) * fpart; + sample = (s >> SHIFT); + } + else //16 bit signed (endianness?) + { + int16_t p1 = read_word(SA(slot) + addr1); + int16_t p2 = read_word(SA(slot) + addr2); + int32_t s; + int32_t fpart = slot->cur_addr & ((1 << SHIFT) - 1); + s = (int)(p1) * ((1 << SHIFT) - fpart) + (int)(p2) * fpart; + sample = (s >> SHIFT); + } } + else if (SSCTL(slot) == 1) // Internally generated data (Noise) + sample = (int16_t)(machine().rand() & 0xffff); // Unknown algorithm + else if (SSCTL(slot) >= 2) // Internally generated data (All 0) + sample = 0; - if(SBCTL(slot)&0x1) + if (SBCTL(slot) & 0x1) sample ^= 0x7FFF; - if(SBCTL(slot)&0x2) - sample = (int16_t)(sample^0x8000); + if (SBCTL(slot) & 0x2) + sample = (int16_t)(sample ^ 0x8000); - if(slot->Backwards) - slot->cur_addr-=step; + if (slot->Backwards) + slot->cur_addr -= step; else - slot->cur_addr+=step; - slot->nxt_addr=slot->cur_addr+(1<cur_addr += step; + slot->nxt_addr = slot->cur_addr + (1 << SHIFT); - addr1=slot->cur_addr>>SHIFT; - addr2=slot->nxt_addr>>SHIFT; + addr1 = slot->cur_addr >> SHIFT; + addr2 = slot->nxt_addr >> SHIFT; - if(addr1>=LSA(slot) && !(slot->Backwards)) + if (addr1 >= LSA(slot) && !(slot->Backwards)) { - if(LPSLNK(slot) && slot->EG.state==SCSP_ATTACK) + if (LPSLNK(slot) && slot->EG.state == SCSP_ATTACK) slot->EG.state = SCSP_DECAY1; } - for (addr_select=0;addr_select<2;addr_select++) + for (addr_select = 0; addr_select < 2; addr_select++) { int32_t rem_addr; - switch(LPCTL(slot)) + switch (LPCTL(slot)) { case 0: //no loop - if(*addr[addr_select]>=LSA(slot) && *addr[addr_select]>=LEA(slot)) + if (*addr[addr_select] >= LSA(slot) && *addr[addr_select] >= LEA(slot)) { - //slot->active=0; - StopSlot(slot,0); + //slot->active=0; + StopSlot(slot, 0); } break; case 1: //normal loop - if(*addr[addr_select]>=LEA(slot)) + if (*addr[addr_select] >= LEA(slot)) { - rem_addr = *slot_addr[addr_select] - (LEA(slot)<=LSA(slot)) && !(slot->Backwards)) + if ((*addr[addr_select] >= LSA(slot)) && !(slot->Backwards)) { - rem_addr = *slot_addr[addr_select] - (LSA(slot)<Backwards=1; + rem_addr = *slot_addr[addr_select] - (LSA(slot) << SHIFT); + *slot_addr[addr_select] = (LEA(slot) << SHIFT) - rem_addr; + slot->Backwards = 1; } - else if((*addr[addr_select]Backwards) + else if ((*addr[addr_select] < LSA(slot) || (*slot_addr[addr_select] & 0x80000000)) && slot->Backwards) { - rem_addr = (LSA(slot)<=LEA(slot)) //reached end, reverse till start + if (*addr[addr_select] >= LEA(slot)) //reached end, reverse till start { - rem_addr = *slot_addr[addr_select] - (LEA(slot)<Backwards=1; + rem_addr = *slot_addr[addr_select] - (LEA(slot) << SHIFT); + *slot_addr[addr_select] = (LEA(slot) << SHIFT) - rem_addr; + slot->Backwards = 1; } - else if((*addr[addr_select]Backwards)//reached start or negative + else if ((*addr[addr_select] < LSA(slot) || (*slot_addr[addr_select] & 0x80000000)) && slot->Backwards)//reached start or negative { - rem_addr = (LSA(slot)<Backwards=0; + rem_addr = (LSA(slot) << SHIFT) - *slot_addr[addr_select]; + *slot_addr[addr_select] = (LSA(slot) << SHIFT) + rem_addr; + slot->Backwards = 0; } break; } } - if(!SDIR(slot)) + if (!SDIR(slot)) { - if(ALFOS(slot)!=0) + if (ALFOS(slot) != 0) { - sample=sample*ALFO_Step(&(slot->ALFO)); - sample>>=SHIFT; + sample = sample * ALFO_Step(&(slot->ALFO)); + sample >>= SHIFT; } - if(slot->EG.state==SCSP_ATTACK) - sample=(sample*EG_Update(slot))>>SHIFT; + if (slot->EG.state == SCSP_ATTACK) + sample = (sample * EG_Update(slot)) >> SHIFT; else - sample=(sample*m_EG_TABLE[EG_Update(slot)>>(SHIFT-10)])>>SHIFT; + sample = (sample * m_EG_TABLE[EG_Update(slot) >> (SHIFT - 10)]) >> SHIFT; } - if(!STWINH(slot)) + if (!STWINH(slot)) { - if(!SDIR(slot)) + if (!SDIR(slot)) { - unsigned short Enc=((TL(slot))<<0x0)|(0x7<<0xd); - *m_RBUFDST=(sample*m_LPANTABLE[Enc])>>(SHIFT+1); + uint16_t Enc = ((TL(slot)) << 0x0) | (0x7 << 0xd); + *m_RBUFDST = (sample * m_LPANTABLE[Enc]) >> (SHIFT + 1); } else { - unsigned short Enc=(0<<0x0)|(0x7<<0xd); - *m_RBUFDST=(sample*m_LPANTABLE[Enc])>>(SHIFT+1); + uint16_t Enc = (0 << 0x0) | (0x7 << 0xd); + *m_RBUFDST = (sample * m_LPANTABLE[Enc]) >> (SHIFT + 1); } } @@ -1312,76 +1291,72 @@ void scsp_device::DoMasterSamples(int nsamples) { stream_sample_t *bufr,*bufl; stream_sample_t *exts[2]; - int sl, s, i; - bufr=m_bufferr; - bufl=m_bufferl; - exts[0]=m_exts0; - exts[1]=m_exts1; + bufr = m_bufferr; + bufl = m_bufferl; + exts[0] = m_exts0; + exts[1] = m_exts1; - for(s=0;s>(SHIFT-2),ISEL(slot),IMXL(slot)); - Enc=((TL(slot))<<0x0)|((DIPAN(slot))<<0x8)|((DISDL(slot))<<0xd); + Enc = ((TL(slot)) << 0x0) | ((IMXL(slot)) << 0xd); + m_DSP.SetSample((sample*m_LPANTABLE[Enc]) >> (SHIFT-2), ISEL(slot), IMXL(slot)); + Enc = ((TL(slot)) << 0x0) | ((DIPAN(slot)) << 0x8) | ((DISDL(slot)) << 0xd); { - smpl+=(sample*m_LPANTABLE[Enc])>>SHIFT; - smpr+=(sample*m_RPANTABLE[Enc])>>SHIFT; + smpl += (sample * m_LPANTABLE[Enc]) >> SHIFT; + smpr += (sample * m_RPANTABLE[Enc]) >> SHIFT; } } #if SCSP_FM_DELAY - m_RINGBUF[(m_BUFPTR+64-(SCSP_FM_DELAY-1))&63] = m_DELAYBUF[(m_DELAYPTR+SCSP_FM_DELAY-(SCSP_FM_DELAY-1))%SCSP_FM_DELAY]; + m_RINGBUF[(m_BUFPTR + 64 - (SCSP_FM_DELAY - 1)) & 63] = m_DELAYBUF[(m_DELAYPTR + SCSP_FM_DELAY - (SCSP_FM_DELAY - 1)) % SCSP_FM_DELAY]; #endif ++m_BUFPTR; - m_BUFPTR&=63; + m_BUFPTR &= 63; #if SCSP_FM_DELAY ++m_DELAYPTR; - if(m_DELAYPTR>SCSP_FM_DELAY-1) m_DELAYPTR=0; + if (m_DELAYPTR > SCSP_FM_DELAY-1) m_DELAYPTR = 0; #endif } m_DSP.Step(); - for(i=0;i<16;++i) + for (int i = 0; i < 16; ++i) { - SCSP_SLOT *slot=m_Slots+i; - if(EFSDL(slot)) + SCSP_SLOT *slot = m_Slots + i; + if (EFSDL(slot)) { - unsigned short Enc=((EFPAN(slot))<<0x8)|((EFSDL(slot))<<0xd); - smpl+=(m_DSP.EFREG[i]*m_LPANTABLE[Enc])>>SHIFT; - smpr+=(m_DSP.EFREG[i]*m_RPANTABLE[Enc])>>SHIFT; + uint16_t Enc = ((EFPAN(slot)) << 0x8) | ((EFSDL(slot)) << 0xd); + smpl += (m_DSP.EFREG[i] * m_LPANTABLE[Enc]) >> SHIFT; + smpr += (m_DSP.EFREG[i] * m_RPANTABLE[Enc]) >> SHIFT; } } - for(i=0;i<2;++i) + for (int i = 0; i < 2; ++i) { - SCSP_SLOT *slot=m_Slots+i+16; // 100217, 100237 EFSDL, EFPAN for EXTS0/1 - if(EFSDL(slot)) + SCSP_SLOT *slot = m_Slots + i + 16; // 100217, 100237 EFSDL, EFPAN for EXTS0/1 + if (EFSDL(slot)) { m_DSP.EXTS[i] = exts[i][s]; - unsigned short Enc=((EFPAN(slot))<<0x8)|((EFSDL(slot))<<0xd); - smpl+=(m_DSP.EXTS[i]*m_LPANTABLE[Enc])>>SHIFT; - smpr+=(m_DSP.EXTS[i]*m_RPANTABLE[Enc])>>SHIFT; + uint16_t Enc = ((EFPAN(slot)) << 0x8) | ((EFSDL(slot)) << 0xd); + smpl += (m_DSP.EXTS[i] * m_LPANTABLE[Enc]) >> SHIFT; + smpr += (m_DSP.EXTS[i] * m_RPANTABLE[Enc]) >> SHIFT; } } @@ -1392,8 +1367,8 @@ void scsp_device::DoMasterSamples(int nsamples) } else { - smpl = clip16(smpl>>2); - smpr = clip16(smpr>>2); + smpl = clip16(smpl >> 2); + smpr = clip16(smpr >> 2); } *bufl++ = smpl; @@ -1409,75 +1384,75 @@ void scsp_device::exec_dma() logerror("SCSP: DMA transfer START\n" "DMEA: %04x DRGA: %04x DTLG: %04x\n" - "DGATE: %d DDIR: %d\n",m_dma.dmea,m_dma.drga,m_dma.dtlg,m_dma.dgate ? 1 : 0,m_dma.ddir ? 1 : 0); + "DGATE: %d DDIR: %d\n", m_dma.dmea, m_dma.drga, m_dma.dtlg, m_dma.dgate ? 1 : 0, m_dma.ddir ? 1 : 0); /* Copy the dma values in a temp storage for resuming later */ /* (DMA *can't* overwrite its parameters). */ - if(!(m_dma.ddir)) + if (!(m_dma.ddir)) { - for(i=0;i<3;i++) - tmp_dma[i] = m_udata.data[(0x12+(i*2))/2]; + for (i = 0; i < 3; i++) + tmp_dma[i] = m_udata.data[(0x12 + (i * 2)) / 2]; } /* note: we don't use space.read_word / write_word because it can happen that SH-2 enables the DMA instead of m68k. */ /* TODO: don't know if params auto-updates, I guess not ... */ - if(m_dma.ddir) + if (m_dma.ddir) { - if(m_dma.dgate) + if (m_dma.dgate) { popmessage("Check: SCSP DMA DGATE enabled, contact MAME/MESSdev"); - for(i=0;i < m_dma.dtlg;i+=2) + for (i = 0; i < m_dma.dtlg; i += 2) { this->space().write_word(m_dma.dmea, 0); - m_dma.dmea+=2; + m_dma.dmea += 2; } } else { - for(i=0;i < m_dma.dtlg;i+=2) + for (i = 0; i < m_dma.dtlg; i += 2) { uint16_t tmp; tmp = r16(m_dma.drga); this->space().write_word(m_dma.dmea, tmp); - m_dma.dmea+=2; - m_dma.drga+=2; + m_dma.dmea += 2; + m_dma.drga += 2; } } } else { - if(m_dma.dgate) + if (m_dma.dgate) { popmessage("Check: SCSP DMA DGATE enabled, contact MAME/MESSdev"); - for(i=0;i < m_dma.dtlg;i+=2) + for (i = 0; i < m_dma.dtlg; i += 2) { w16(m_dma.drga, 0); - m_dma.drga+=2; + m_dma.drga += 2; } } else { - for(i=0;i < m_dma.dtlg;i+=2) + for (i = 0; i < m_dma.dtlg; i += 2) { uint16_t tmp = read_word(m_dma.dmea); w16(m_dma.drga, tmp); - m_dma.dmea+=2; - m_dma.drga+=2; + m_dma.dmea += 2; + m_dma.drga += 2; } } } /*Resume the values*/ - if(!(m_dma.ddir)) + if (!(m_dma.ddir)) { - for(i=0;i<3;i++) - m_udata.data[(0x12+(i*2))/2] = tmp_dma[i]; + for (i = 0; i < 3; i++) + m_udata.data[(0x12 + (i * 2)) / 2] = tmp_dma[i]; } /* Job done */ m_udata.data[0x16/2] &= ~0x1000; /* request a dma end irq (TODO: make it inside the interface) */ - if(m_udata.data[0x1e/2] & 0x10) + if (m_udata.data[0x1e/2] & 0x10) { popmessage("SCSP DMA IRQ triggered, contact MAMEdev"); m_irq_cb(DecodeSCI(SCIDMA), HOLD_LINE); @@ -1496,25 +1471,23 @@ int IRQCB(void *param) READ16_MEMBER( scsp_device::read ) { m_stream->update(); - return r16(offset*2); + return r16(offset * 2); } WRITE16_MEMBER( scsp_device::write ) { - uint16_t tmp; - m_stream->update(); - tmp = r16(offset*2); + uint16_t tmp = r16(offset * 2); COMBINE_DATA(&tmp); - w16(offset*2, tmp); + w16(offset * 2, tmp); } void scsp_device::midi_in(u8 data) { // printf("scsp_midi_in: %02x\n", data); - m_MidiStack[m_MidiW++]=data; + m_MidiStack[m_MidiW++] = data; m_MidiW &= 31; CheckPendingIRQ(); @@ -1522,150 +1495,149 @@ void scsp_device::midi_in(u8 data) READ16_MEMBER( scsp_device::midi_out_r ) { - unsigned char val; + uint8_t val; - val=m_MidiStack[m_MidiR++]; - m_MidiR&=31; + val = m_MidiStack[m_MidiR++]; + m_MidiR &= 31; return val; } //LFO handling -#define LFIX(v) ((unsigned int) ((float) (1<phase+=LFO->phase_step; + LFO->phase += LFO->phase_step; #if LFO_SHIFT!=8 - LFO->phase&=(1<<(LFO_SHIFT+8))-1; + LFO->phase &= (1 << (LFO_SHIFT + 8)) - 1; #endif - p=LFO->table[LFO->phase>>LFO_SHIFT]; + p=LFO->table[LFO->phase >> LFO_SHIFT]; p=LFO->scale[p+128]; - return p<<(SHIFT-LFO_SHIFT); + return p << (SHIFT - LFO_SHIFT); } -signed int scsp_device::ALFO_Step(SCSP_LFO_t *LFO) +int32_t scsp_device::ALFO_Step(SCSP_LFO_t *LFO) { int p; - LFO->phase+=LFO->phase_step; + LFO->phase += LFO->phase_step; #if LFO_SHIFT!=8 - LFO->phase&=(1<<(LFO_SHIFT+8))-1; + LFO->phase &= (1 << (LFO_SHIFT + 8)) - 1; #endif - p=LFO->table[LFO->phase>>LFO_SHIFT]; + p=LFO->table[LFO->phase >> LFO_SHIFT]; p=LFO->scale[p]; - return p<<(SHIFT-LFO_SHIFT); + return p << (SHIFT - LFO_SHIFT); } void scsp_device::LFO_ComputeStep(SCSP_LFO_t *LFO,uint32_t LFOF,uint32_t LFOWS,uint32_t LFOS,int ALFO) { - float step=(float) LFOFreq[LFOF]*256.0f/44100.0f; - LFO->phase_step=(unsigned int) ((float) (1<phase_step = (uint32_t) ((float) (1 << LFO_SHIFT) * step); + if (ALFO) { - switch(LFOWS) + switch (LFOWS) { - case 0: LFO->table=m_ALFO_SAW; break; - case 1: LFO->table=m_ALFO_SQR; break; - case 2: LFO->table=m_ALFO_TRI; break; - case 3: LFO->table=m_ALFO_NOI; break; + case 0: LFO->table = m_ALFO_SAW; break; + case 1: LFO->table = m_ALFO_SQR; break; + case 2: LFO->table = m_ALFO_TRI; break; + case 3: LFO->table = m_ALFO_NOI; break; } - LFO->scale=m_ASCALES[LFOS]; + LFO->scale = m_ASCALES[LFOS]; } else { - switch(LFOWS) + switch (LFOWS) { - case 0: LFO->table=m_PLFO_SAW; break; - case 1: LFO->table=m_PLFO_SQR; break; - case 2: LFO->table=m_PLFO_TRI; break; - case 3: LFO->table=m_PLFO_NOI; break; + case 0: LFO->table = m_PLFO_SAW; break; + case 1: LFO->table = m_PLFO_SQR; break; + case 2: LFO->table = m_PLFO_TRI; break; + case 3: LFO->table = m_PLFO_NOI; break; } - LFO->scale=m_PSCALES[LFOS]; + LFO->scale = m_PSCALES[LFOS]; } } diff --git a/src/devices/sound/scsp.h b/src/devices/sound/scsp.h index 836086fac78..50e42bc03c8 100644 --- a/src/devices/sound/scsp.h +++ b/src/devices/sound/scsp.h @@ -173,7 +173,6 @@ private: TIMER_CALLBACK_MEMBER( timerC_cb ); int Get_AR(int base, int R); int Get_DR(int base, int R); - int Get_RR(int base, int R); void Compute_EG(SCSP_SLOT *slot); int EG_Update(SCSP_SLOT *slot); uint32_t Step(SCSP_SLOT *slot); diff --git a/src/devices/sound/scspdsp.cpp b/src/devices/sound/scspdsp.cpp index a30f3af65d3..678411b361f 100644 --- a/src/devices/sound/scspdsp.cpp +++ b/src/devices/sound/scspdsp.cpp @@ -61,7 +61,7 @@ static int32_t UNPACK(uint16_t val) void SCSPDSP::Init() { std::memset(this, 0, sizeof(*this)); - RBL = 0x8000; + RBL = (8*1024); // Initial RBL is 0 Stopped = true; } @@ -80,8 +80,6 @@ void SCSPDSP::Step() #endif int32_t ACC = 0; //26 bit - int32_t SHIFTED = 0; //24 bit - int32_t Y = 0; //13 bit int32_t MEMVAL = 0; int32_t FRC_REG = 0; //13 bit int32_t Y_REG = 0; //24 bit @@ -210,6 +208,7 @@ void SCSPDSP::Step() //X |= 0xFF000000; } + int32_t Y = 0; //13 bit if (YSEL == 0) Y = FRC_REG; else if (YSEL == 1) @@ -223,6 +222,7 @@ void SCSPDSP::Step() Y_REG = INPUTS; //Shifter + int32_t SHIFTED = 0; //24 bit if (SHIFT == 0) SHIFTED = std::max(std::min(ACC, 0x007FFFFF), -0x00800000); else if (SHIFT == 1) @@ -236,7 +236,7 @@ void SCSPDSP::Step() //if (SHIFTED & 0x00800000) //SHIFTED |= 0xFF000000; } - else if(SHIFT==3) + else if (SHIFT == 3) { SHIFTED = ACC; SHIFTED <<= 8; -- cgit v1.2.3