diff --git a/src/engine/platform/ay.cpp b/src/engine/platform/ay.cpp index 9f4e0dc2..ad133c08 100644 --- a/src/engine/platform/ay.cpp +++ b/src/engine/platform/ay.cpp @@ -115,7 +115,7 @@ const unsigned char dacLogTableAY[256]={ void DivPlatformAY8910::runDAC() { for (int i=0; i<3; i++) { - if (chan[i].psgMode.dac && chan[i].dac.sample!=-1) { + if (chan[i].active && chan[i].psgMode.dac && chan[i].dac.sample!=-1) { chan[i].dac.period+=chan[i].dac.rate; bool end=false; bool changed=false; @@ -129,7 +129,7 @@ void DivPlatformAY8910::runDAC() { break; } unsigned char dacData=dacLogTableAY[(unsigned char)s->data8[chan[i].dac.pos]^0x80]; - chan[i].dac.out=MAX(0,dacData-(15-chan[i].outVol)); + chan[i].dac.out=(chan[i].active && !isMuted[i])?MAX(0,dacData-(15-chan[i].outVol)):0; if (prevOut!=chan[i].dac.out) { prevOut=chan[i].dac.out; changed=true; @@ -264,7 +264,7 @@ void DivPlatformAY8910::tick(bool sysTick) { } if (chan[i].std.wave.had) { if (!chan[i].psgMode.dac) { - chan[i].psgMode=(chan[i].std.wave.val+1)&7; + chan[i].psgMode.val=(chan[i].std.wave.val+1)&7; if (isMuted[i]) { rWrite(0x08+i,0); } else if (intellivision && (chan[i].psgMode.getEnvelope())) { @@ -336,8 +336,12 @@ void DivPlatformAY8910::tick(bool sysTick) { if (chan[i].keyOn) { //rWrite(16+i*5+1,((chan[i].duty&3)<<6)|(63-(ins->gb.soundLen&63))); //rWrite(16+i*5+2,((chan[i].vol<<4))|(ins->gb.envLen&7)|((ins->gb.envDir&1)<<3)); + if (chan[i].psgMode.val==0) { + chan[i].psgMode.val=1; + } } if (chan[i].keyOff) { + chan[i].psgMode.val=0; rWrite(0x08+i,0); } rWrite((i)<<1,chan[i].freq&0xff); @@ -543,7 +547,7 @@ int DivPlatformAY8910::dispatch(DivCommand c) { case DIV_CMD_STD_NOISE_MODE: if (!chan[c.chan].psgMode.dac) { if (c.value<16) { - chan[c.chan].psgMode=(c.value+1)&7; + chan[c.chan].psgMode.val=(c.value+1)&7; if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else if (chan[c.chan].active) { diff --git a/src/engine/platform/ay.h b/src/engine/platform/ay.h index ec9a14fe..e359b3d7 100644 --- a/src/engine/platform/ay.h +++ b/src/engine/platform/ay.h @@ -32,10 +32,15 @@ class DivPlatformAY8910: public DivDispatch { inline unsigned char regRemap(unsigned char reg) { return intellivision?AY8914RegRemap[reg&0x0f]:reg&0x0f; } struct Channel { struct PSGMode { - unsigned char tone: 1; - unsigned char noise: 1; - unsigned char envelope: 1; - unsigned char dac: 1; + union { + struct { + unsigned char tone: 1; + unsigned char noise: 1; + unsigned char envelope: 1; + unsigned char dac: 1; + }; + unsigned char val=1; + }; unsigned char getTone() { return dac?0:(tone<<0); @@ -49,19 +54,8 @@ class DivPlatformAY8910: public DivDispatch { return dac?0:(envelope<<2); } - PSGMode& operator=(unsigned char s) { - tone=(s>>0)&1; - noise=(s>>1)&1; - envelope=(s>>2)&1; - dac=(s>>3)&1; - return *this; - } - PSGMode(): - tone(1), - noise(0), - envelope(0), - dac(0) {} + val(1) {} } psgMode; struct DAC { diff --git a/src/engine/platform/ay8930.cpp b/src/engine/platform/ay8930.cpp index a1182a80..412d53f9 100644 --- a/src/engine/platform/ay8930.cpp +++ b/src/engine/platform/ay8930.cpp @@ -110,8 +110,8 @@ const unsigned char dacLogTableAY8930[256]={ }; void DivPlatformAY8930::runDAC() { - for (int i=0; i<3; i++) { - if (chan[i].psgMode.dac && chan[i].dac.sample!=-1) { + for (int i=0; i<3; i++) { + if (chan[i].active && chan[i].psgMode.dac && chan[i].dac.sample!=-1) { chan[i].dac.period+=chan[i].dac.rate; bool end=false; bool changed=false; @@ -125,7 +125,7 @@ void DivPlatformAY8930::runDAC() { break; } unsigned char dacData=dacLogTableAY8930[(unsigned char)s->data8[chan[i].dac.pos]^0x80]; - chan[i].dac.out=MAX(0,dacData-(31-chan[i].outVol)); + chan[i].dac.out=(chan[i].active && !isMuted[i])?MAX(0,dacData-(31-chan[i].outVol)):0; if (prevOut!=chan[i].dac.out) { prevOut=chan[i].dac.out; changed=true; @@ -254,7 +254,7 @@ void DivPlatformAY8930::tick(bool sysTick) { } if (chan[i].std.wave.had) { if (!chan[i].psgMode.dac) { - chan[i].psgMode=(chan[i].std.wave.val+1)&7; + chan[i].psgMode.val=(chan[i].std.wave.val+1)&7; if (isMuted[i]) { rWrite(0x08+i,0); } else { @@ -333,12 +333,16 @@ void DivPlatformAY8930::tick(bool sysTick) { } if (chan[i].freq>65535) chan[i].freq=65535; if (chan[i].keyOn) { + if (chan[i].psgMode.val==0) { + chan[i].psgMode.val=1; + } if (chan[i].insChanged) { if (!chan[i].std.ex1.will) immWrite(0x16+i,chan[i].duty); chan[i].insChanged=false; } } if (chan[i].keyOff) { + chan[i].psgMode.val=0; rWrite(0x08+i,0); } rWrite((i)<<1,chan[i].freq&0xff); @@ -537,7 +541,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) { case DIV_CMD_STD_NOISE_MODE: if (c.value<0x10) { if (!chan[c.chan].psgMode.dac) { - chan[c.chan].psgMode=(c.value+1)&7; + chan[c.chan].psgMode.val=(c.value+1)&7; if (isMuted[c.chan]) { rWrite(0x08+c.chan,0); } else if (chan[c.chan].active) { diff --git a/src/engine/platform/ay8930.h b/src/engine/platform/ay8930.h index 441e8214..fdfaa7a6 100644 --- a/src/engine/platform/ay8930.h +++ b/src/engine/platform/ay8930.h @@ -40,10 +40,15 @@ class DivPlatformAY8930: public DivDispatch { } envelope; struct PSGMode { - unsigned char tone: 1; - unsigned char noise: 1; - unsigned char envelope: 1; - unsigned char dac: 1; + union { + struct { + unsigned char tone: 1; + unsigned char noise: 1; + unsigned char envelope: 1; + unsigned char dac: 1; + }; + unsigned char val=1; + }; unsigned char getTone() { return dac?0:(tone<<0); @@ -57,19 +62,8 @@ class DivPlatformAY8930: public DivDispatch { return dac?0:(envelope<<2); } - PSGMode& operator=(unsigned char s) { - tone=(s>>0)&1; - noise=(s>>1)&1; - envelope=(s>>2)&1; - dac=(s>>3)&1; - return *this; - } - PSGMode(): - tone(1), - noise(0), - envelope(0), - dac(0) {} + val(1) {} } psgMode; struct DAC { diff --git a/src/engine/song.h b/src/engine/song.h index a9a16263..b708ac0f 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -617,7 +617,7 @@ struct DivSong { e1e2StopOnSameNote(false), brokenPortaArp(false), snNoLowPeriods(false), - disableSampleMacro(true), + disableSampleMacro(false), autoSystem(true) { for (int i=0; i<32; i++) { system[i]=DIV_SYSTEM_NULL;