AY: don't use bit arrays

issue #649
This commit is contained in:
tildearrow 2023-08-11 23:58:44 -05:00
parent 7be0079c62
commit 5f2cfd4854
5 changed files with 74 additions and 95 deletions

View file

@ -111,7 +111,7 @@ const unsigned char dacLogTableAY8930[256]={
void DivPlatformAY8930::runDAC() {
for (int i=0; i<3; i++) {
if (chan[i].active && chan[i].curPSGMode.dac && chan[i].dac.sample!=-1) {
if (chan[i].active && (chan[i].curPSGMode.val&8) && chan[i].dac.sample!=-1) {
chan[i].dac.period+=chan[i].dac.rate;
bool end=false;
bool changed=false;
@ -235,7 +235,7 @@ void DivPlatformAY8930::tick(bool sysTick) {
if (chan[i].std.vol.had) {
chan[i].outVol=MIN(31,chan[i].std.vol.val)-(31-(chan[i].vol&31));
if (chan[i].outVol<0) chan[i].outVol=0;
if (!chan[i].nextPSGMode.dac) {
if (!(chan[i].nextPSGMode.val&8)) {
if (isMuted[i]) {
rWrite(0x08+i,0);
} else {
@ -255,7 +255,7 @@ void DivPlatformAY8930::tick(bool sysTick) {
rWrite(0x06,chan[i].std.duty.val);
}
if (chan[i].std.wave.had) {
if (!chan[i].nextPSGMode.dac) {
if (!(chan[i].nextPSGMode.val&8)) {
chan[i].nextPSGMode.val=(chan[i].std.wave.val+1)&7;
if (chan[i].active) {
chan[i].curPSGMode.val=chan[i].nextPSGMode.val;
@ -278,7 +278,7 @@ void DivPlatformAY8930::tick(bool sysTick) {
}
if (chan[i].std.phaseReset.had) {
if (chan[i].std.phaseReset.val==1) {
if (chan[i].nextPSGMode.dac) {
if (chan[i].nextPSGMode.val&8) {
if (dumpWrites) addWrite(0xffff0002+(i<<8),0);
if (chan[i].dac.sample<0 || chan[i].dac.sample>=parent->song.sampleLen) {
if (dumpWrites) {
@ -337,7 +337,7 @@ void DivPlatformAY8930::tick(bool sysTick) {
if (chan[i].freq<0) chan[i].freq=0;
if (chan[i].freq>65535) chan[i].freq=65535;
if (chan[i].keyOn) {
if (!chan[i].nextPSGMode.dac) {
if (!(chan[i].nextPSGMode.val&8)) {
chan[i].curPSGMode.val=chan[i].nextPSGMode.val;
}
if (chan[i].insChanged) {
@ -397,11 +397,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
case DIV_CMD_NOTE_ON: {
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_AY8930);
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) {
chan[c.chan].nextPSGMode.dac=true;
chan[c.chan].nextPSGMode.val|=8;
} else if (chan[c.chan].dac.furnaceDAC) {
chan[c.chan].nextPSGMode.dac=false;
chan[c.chan].nextPSGMode.val&=~8;
}
if (chan[c.chan].nextPSGMode.dac) {
if (chan[c.chan].nextPSGMode.val&8) {
if (skipRegisterWrites) break;
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) {
if (c.value!=DIV_NOTE_NULL) {
@ -453,7 +453,8 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
}
chan[c.chan].dac.furnaceDAC=false;
}
chan[c.chan].curPSGMode.dac=chan[c.chan].nextPSGMode.dac;
chan[c.chan].curPSGMode.val&=~8;
chan[c.chan].curPSGMode.val|=chan[c.chan].nextPSGMode.val&8;
break;
}
if (c.value!=DIV_NOTE_NULL) {
@ -467,7 +468,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) {
chan[c.chan].outVol=chan[c.chan].vol;
}
if (!chan[c.chan].nextPSGMode.dac) {
if (!(chan[c.chan].nextPSGMode.val&8)) {
if (isMuted[c.chan]) {
rWrite(0x08+c.chan,0);
} else {
@ -479,7 +480,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
case DIV_CMD_NOTE_OFF:
chan[c.chan].dac.sample=-1;
if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0);
chan[c.chan].nextPSGMode.dac=false;
chan[c.chan].nextPSGMode.val&=~8;
chan[c.chan].keyOff=true;
chan[c.chan].active=false;
chan[c.chan].macroInit(NULL);
@ -493,7 +494,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
if (!chan[c.chan].std.vol.has) {
chan[c.chan].outVol=c.value;
}
if (!chan[c.chan].nextPSGMode.dac) {
if (!(chan[c.chan].nextPSGMode.val&8)) {
if (isMuted[c.chan]) {
rWrite(0x08+c.chan,0);
} else {
@ -548,7 +549,7 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
}
case DIV_CMD_STD_NOISE_MODE:
if (c.value<0x10) {
if (!chan[c.chan].nextPSGMode.dac) {
if (!(chan[c.chan].nextPSGMode.val&8)) {
chan[c.chan].nextPSGMode.val=(c.value+1)&7;
if (chan[c.chan].active) {
chan[c.chan].curPSGMode.val=chan[c.chan].nextPSGMode.val;
@ -571,11 +572,11 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
chan[c.chan].envelope.mode=c.value>>4;
rWrite(regMode[c.chan],chan[c.chan].envelope.mode);
if (c.value&15) {
chan[c.chan].nextPSGMode.envelope|=1;
chan[c.chan].nextPSGMode.val|=4;
} else {
chan[c.chan].nextPSGMode.envelope&=~1;
chan[c.chan].nextPSGMode.val&=~4;
}
if (!chan[c.chan].nextPSGMode.dac && chan[c.chan].active) {
if (!(chan[c.chan].nextPSGMode.val&8) && chan[c.chan].active) {
chan[c.chan].curPSGMode.val=chan[c.chan].nextPSGMode.val;
}
if (isMuted[c.chan]) {
@ -630,8 +631,15 @@ int DivPlatformAY8930::dispatch(DivCommand c) {
immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal));
break;
case DIV_CMD_SAMPLE_MODE:
chan[c.chan].nextPSGMode.dac=(c.value>0)?1:0;
chan[c.chan].curPSGMode.dac=chan[c.chan].nextPSGMode.dac;
if (c.value>0) {
chan[c.chan].nextPSGMode.val|=8;
} else {
chan[c.chan].nextPSGMode.val&=~8;
}
if (chan[c.chan].active) {
chan[c.chan].curPSGMode.val&=~8;
chan[c.chan].curPSGMode.val|=chan[c.chan].nextPSGMode.val&8;
}
break;
case DIV_CMD_SAMPLE_BANK:
sampleBank=c.value;
@ -672,7 +680,7 @@ void DivPlatformAY8930::muteChannel(int ch, bool mute) {
if (isMuted[ch]) {
rWrite(0x08+ch,0);
} else if (chan[ch].active) {
if (chan[ch].nextPSGMode.dac) {
if (chan[ch].nextPSGMode.val&8) {
rWrite(0x08+ch,chan[ch].dac.out&31);
} else {
rWrite(0x08+ch,(chan[ch].outVol&31)|((chan[ch].nextPSGMode.getEnvelope())<<3));