YM2610(B): AY unification

as of now the SSG part of these chips is handled by a DivPlatformAY8910
within the DivPlatformYM2610.
this means less code duplication and therefore prepares for
OPN/OPNA support.
This commit is contained in:
tildearrow 2022-04-06 18:03:30 -05:00
parent 878d3fab1f
commit 2e327953e8
9 changed files with 96 additions and 421 deletions

View file

@ -335,7 +335,7 @@ class DivDispatch {
/** /**
* set skip reg writes. * set skip reg writes.
*/ */
void setSkipRegisterWrites(bool value); virtual void setSkipRegisterWrites(bool value);
/** /**
* notify instrument change. * notify instrument change.

View file

@ -493,6 +493,10 @@ int DivPlatformAY8910::getRegisterPoolSize() {
return 16; return 16;
} }
void DivPlatformAY8910::flushWrites() {
while (!writes.empty()) writes.pop();
}
void DivPlatformAY8910::reset() { void DivPlatformAY8910::reset() {
while (!writes.empty()) writes.pop(); while (!writes.empty()) writes.pop();
ay->device_reset(); ay->device_reset();

View file

@ -87,6 +87,7 @@ class DivPlatformAY8910: public DivDispatch {
void* getChanState(int chan); void* getChanState(int chan);
unsigned char* getRegisterPool(); unsigned char* getRegisterPool();
int getRegisterPoolSize(); int getRegisterPoolSize();
void flushWrites();
void reset(); void reset();
void forceIns(); void forceIns();
void tick(); void tick();

View file

@ -364,106 +364,12 @@ void DivPlatformYM2610::acquire(short* bufL, short* bufR, size_t start, size_t l
void DivPlatformYM2610::tick() { void DivPlatformYM2610::tick() {
// PSG // PSG
for (int i=4; i<7; i++) { ay->tick();
chan[i].std.next(); ay->flushWrites();
if (chan[i].std.hadVol) { for (DivRegWrite& i: ay->getRegisterWrites()) {
chan[i].outVol=MIN(15,chan[i].std.vol)-(15-(chan[i].vol&15)); immWrite(i.addr&15,i.val);
if (chan[i].outVol<0) chan[i].outVol=0;
if (isMuted[i]) {
rWrite(0x04+i,0);
} else {
rWrite(0x04+i,(chan[i].outVol&15)|((chan[i].psgMode&4)<<2));
}
}
if (chan[i].std.hadArp) {
if (!chan[i].inPorta) {
if (chan[i].std.arpMode) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].std.arp);
} else {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note+chan[i].std.arp);
}
}
chan[i].freqChanged=true;
} else {
if (chan[i].std.arpMode && chan[i].std.finishedArp) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note);
chan[i].freqChanged=true;
}
}
if (chan[i].std.hadDuty) {
ayNoiseFreq=31-chan[i].std.duty;
rWrite(0x06,ayNoiseFreq);
}
if (chan[i].std.hadWave) {
chan[i].psgMode=(chan[i].std.wave+1)&7;
if (isMuted[i]) {
rWrite(0x04+i,0);
} else {
rWrite(0x04+i,(chan[i].outVol&15)|((chan[i].psgMode&4)<<2));
}
}
if (chan[i].std.hadEx2) {
ayEnvMode=chan[i].std.ex2;
rWrite(0x0d,ayEnvMode);
}
if (chan[i].std.hadEx3) {
chan[i].autoEnvNum=chan[i].std.ex3;
chan[i].freqChanged=true;
if (!chan[i].std.willAlg) chan[i].autoEnvDen=1;
}
if (chan[i].std.hadAlg) {
chan[i].autoEnvDen=chan[i].std.alg;
chan[i].freqChanged=true;
if (!chan[i].std.willEx3) chan[i].autoEnvNum=1;
}
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
if (chan[i].freq>4095) chan[i].freq=4095;
if (chan[i].keyOn) {
}
if (chan[i].keyOff) {
rWrite(0x04+i,0);
}
rWrite((i-4)<<1,chan[i].freq&0xff);
rWrite(1+((i-4)<<1),chan[i].freq>>8);
if (chan[i].keyOn) chan[i].keyOn=false;
if (chan[i].keyOff) chan[i].keyOff=false;
if (chan[i].freqChanged && chan[i].autoEnvNum>0 && chan[i].autoEnvDen>0) {
ayEnvPeriod=(chan[i].freq*chan[i].autoEnvDen/chan[i].autoEnvNum)>>4;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
chan[i].freqChanged=false;
}
}
rWrite(0x07,
~((chan[4].psgMode&1)|
((chan[5].psgMode&1)<<1)|
((chan[6].psgMode&1)<<2)|
((chan[4].psgMode&2)<<2)|
((chan[5].psgMode&2)<<3)|
((chan[6].psgMode&2)<<4)));
if (ayEnvSlide!=0) {
ayEnvSlideLow+=ayEnvSlide;
while (ayEnvSlideLow>7) {
ayEnvSlideLow-=8;
if (ayEnvPeriod<0xffff) {
ayEnvPeriod++;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
}
while (ayEnvSlideLow<-7) {
ayEnvSlideLow+=8;
if (ayEnvPeriod>0) {
ayEnvPeriod--;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
}
} }
ay->getRegisterWrites().clear();
// FM // FM
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
@ -620,7 +526,7 @@ void DivPlatformYM2610::tick() {
chan[13].freqChanged=false; chan[13].freqChanged=false;
} }
for (int i=0; i<512; i++) { for (int i=16; i<512; i++) {
if (pendingWrites[i]!=oldWrites[i]) { if (pendingWrites[i]!=oldWrites[i]) {
immWrite(i,pendingWrites[i]&0xff); immWrite(i,pendingWrites[i]&0xff);
oldWrites[i]=pendingWrites[i]; oldWrites[i]=pendingWrites[i];
@ -686,6 +592,10 @@ int DivPlatformYM2610::toFreq(int freq) {
} }
int DivPlatformYM2610::dispatch(DivCommand c) { int DivPlatformYM2610::dispatch(DivCommand c) {
if (c.chan>3 && c.chan<7) {
c.chan-=4;
return ay->dispatch(c);
}
switch (c.cmd) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
if (c.chan>12) { // ADPCM-B if (c.chan>12) { // ADPCM-B
@ -780,22 +690,6 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
} }
} }
if (c.chan>3) { // PSG
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value;
}
chan[c.chan].active=true;
chan[c.chan].keyOn=true;
if (isMuted[c.chan]) {
rWrite(0x04+c.chan,0);
} else {
rWrite(0x04+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
}
if (chan[c.chan].insChanged) { if (chan[c.chan].insChanged) {
chan[c.chan].state=ins->fm; chan[c.chan].state=ins->fm;
} }
@ -860,10 +754,6 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
immWrite(0x100,0x80|(1<<(c.chan-7))); immWrite(0x100,0x80|(1<<(c.chan-7)));
break; break;
} }
if (c.chan>3) {
chan[c.chan].std.release();
break;
}
chan[c.chan].keyOff=true; chan[c.chan].keyOff=true;
chan[c.chan].keyOn=false; chan[c.chan].keyOn=false;
chan[c.chan].active=false; chan[c.chan].active=false;
@ -885,14 +775,6 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol));
break; break;
} }
if (c.chan>3) { // PSG
if (isMuted[c.chan]) {
rWrite(0x04+c.chan,0);
} else {
if (chan[c.chan].active) rWrite(0x04+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
}
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i]; unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i]; DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
@ -928,7 +810,6 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); immWrite(0x108+(c.chan-7),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol));
break; break;
} }
if (c.chan>3) break;
rWrite(chanOffs[c.chan]+ADDR_LRAF,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(chan[c.chan].state.fms&7)|((chan[c.chan].state.ams&3)<<4)); rWrite(chanOffs[c.chan]+ADDR_LRAF,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(chan[c.chan].state.fms&7)|((chan[c.chan].state.ams&3)<<4));
break; break;
} }
@ -1049,59 +930,6 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
} }
break; break;
} }
case DIV_CMD_STD_NOISE_MODE:
if (c.chan<4 || c.chan>6) break;
chan[c.chan].psgMode=(c.value+1)&7;
if (isMuted[c.chan]) {
rWrite(0x04+c.chan,0);
} else if (chan[c.chan].active) {
rWrite(0x04+c.chan,(chan[c.chan].outVol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
case DIV_CMD_STD_NOISE_FREQ:
if (c.chan<4 || c.chan>6) break;
ayNoiseFreq=31-c.value;
rWrite(0x06,ayNoiseFreq);
break;
case DIV_CMD_AY_ENVELOPE_SET:
if (c.chan<4 || c.chan>6) break;
ayEnvMode=c.value>>4;
rWrite(0x0d,ayEnvMode);
if (c.value&15) {
chan[c.chan].psgMode|=4;
} else {
chan[c.chan].psgMode&=~4;
}
if (isMuted[c.chan]) {
rWrite(0x04+c.chan,0);
} else {
rWrite(0x04+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
case DIV_CMD_AY_ENVELOPE_LOW:
if (c.chan<4 || c.chan>6) break;
ayEnvPeriod&=0xff00;
ayEnvPeriod|=c.value;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_HIGH:
if (c.chan<4 || c.chan>6) break;
ayEnvPeriod&=0xff;
ayEnvPeriod|=c.value<<8;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_SLIDE:
if (c.chan<4 || c.chan>6) break;
ayEnvSlide=c.value;
break;
case DIV_CMD_AY_AUTO_ENVELOPE:
if (c.chan<4 || c.chan>6) break;
chan[c.chan].autoEnvNum=c.value>>4;
chan[c.chan].autoEnvDen=c.value&15;
chan[c.chan].freqChanged=true;
break;
case DIV_ALWAYS_SET_VOLUME: case DIV_ALWAYS_SET_VOLUME:
return 0; return 0;
break; break;
@ -1138,11 +966,7 @@ void DivPlatformYM2610::muteChannel(int ch, bool mute) {
return; return;
} }
if (ch>3) { // PSG if (ch>3) { // PSG
if (isMuted[ch]) { ay->muteChannel(ch-4,mute);
rWrite(0x04+ch,0);
} else {
rWrite(0x04+ch,(chan[ch].outVol&15)|((chan[ch].psgMode&4)<<2));
}
return; return;
} }
// FM // FM
@ -1173,12 +997,16 @@ void DivPlatformYM2610::forceIns() {
chan[i].freqChanged=true; chan[i].freqChanged=true;
} }
} }
for (int i=4; i<14; i++) { for (int i=7; i<14; i++) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8); ay->forceIns();
immWrite(0x0d,ayEnvMode); ay->flushWrites();
for (DivRegWrite& i: ay->getRegisterWrites()) {
immWrite(i.addr&15,i.val);
}
ay->getRegisterWrites().clear();
} }
void* DivPlatformYM2610::getChanState(int ch) { void* DivPlatformYM2610::getChanState(int ch) {
@ -1230,25 +1058,21 @@ void DivPlatformYM2610::reset() {
lastBusy=60; lastBusy=60;
sampleBank=0; sampleBank=0;
ayEnvPeriod=0;
ayEnvMode=0;
ayEnvSlide=0;
ayEnvSlideLow=0;
ayNoiseFreq=0;
delay=0; delay=0;
extMode=false; extMode=false;
// AY noise
immWrite(0x06,ayNoiseFreq);
// LFO // LFO
immWrite(0x22,0x08); immWrite(0x22,0x08);
// PCM volume // PCM volume
immWrite(0x101,0x3f); // A immWrite(0x101,0x3f); // A
immWrite(0x1b,0xff); // B immWrite(0x1b,0xff); // B
ay->reset();
ay->getRegisterWrites().clear();
ay->flushWrites();
} }
bool DivPlatformYM2610::isStereo() { bool DivPlatformYM2610::isStereo() {
@ -1265,12 +1089,16 @@ void DivPlatformYM2610::notifyInsChange(int ins) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
} }
ay->notifyInsChange(ins);
} }
void DivPlatformYM2610::notifyInsDeletion(void* ins) { void DivPlatformYM2610::notifyInsDeletion(void* ins) {
for (int i=4; i<7; i++) { ay->notifyInsDeletion(ins);
chan[i].std.notifyInsDeletion((DivInstrument*)ins); }
}
void DivPlatformYM2610::setSkipRegisterWrites(bool value) {
DivDispatch::setSkipRegisterWrites(value);
ay->setSkipRegisterWrites(value);
} }
int DivPlatformYM2610::init(DivEngine* p, int channels, int sugRate, unsigned int flags) { int DivPlatformYM2610::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
@ -1285,11 +1113,17 @@ int DivPlatformYM2610::init(DivEngine* p, int channels, int sugRate, unsigned in
iface.parent=parent; iface.parent=parent;
iface.sampleBank=0; iface.sampleBank=0;
fm=new ymfm::ym2610(iface); fm=new ymfm::ym2610(iface);
// YM2149, 2MHz
ay=new DivPlatformAY8910;
ay->init(p,3,sugRate,35);
ay->toggleRegisterDump(true);
reset(); reset();
return 14; return 14;
} }
void DivPlatformYM2610::quit() { void DivPlatformYM2610::quit() {
ay->quit();
delete ay;
delete fm; delete fm;
} }

View file

@ -22,6 +22,7 @@
#include "../dispatch.h" #include "../dispatch.h"
#include "../macroInt.h" #include "../macroInt.h"
#include <queue> #include <queue>
#include "ay.h"
#include "sound/ymfm/ymfm_opn.h" #include "sound/ymfm/ymfm_opn.h"
class DivYM2610Interface: public ymfm::ymfm_interface { class DivYM2610Interface: public ymfm::ymfm_interface {
@ -86,10 +87,11 @@ class DivPlatformYM2610: public DivDispatch {
ymfm::ym2610* fm; ymfm::ym2610* fm;
ymfm::ym2610::output_data fmout; ymfm::ym2610::output_data fmout;
DivYM2610Interface iface; DivYM2610Interface iface;
DivPlatformAY8910* ay;
unsigned char regPool[512]; unsigned char regPool[512];
unsigned char lastBusy; unsigned char lastBusy;
int ayNoiseFreq;
unsigned char sampleBank; unsigned char sampleBank;
int delay; int delay;
@ -98,10 +100,6 @@ class DivPlatformYM2610: public DivDispatch {
short oldWrites[512]; short oldWrites[512];
short pendingWrites[512]; short pendingWrites[512];
unsigned char ayEnvMode;
unsigned short ayEnvPeriod;
short ayEnvSlideLow;
short ayEnvSlide;
int octave(int freq); int octave(int freq);
int toFreq(int freq); int toFreq(int freq);
@ -123,6 +121,7 @@ class DivPlatformYM2610: public DivDispatch {
bool keyOffAffectsArp(int ch); bool keyOffAffectsArp(int ch);
void notifyInsChange(int ins); void notifyInsChange(int ins);
void notifyInsDeletion(void* ins); void notifyInsDeletion(void* ins);
void setSkipRegisterWrites(bool val);
void poke(unsigned int addr, unsigned short val); void poke(unsigned int addr, unsigned short val);
void poke(std::vector<DivRegWrite>& wlist); void poke(std::vector<DivRegWrite>& wlist);
const char** getRegisterSheet(); const char** getRegisterSheet();

View file

@ -428,106 +428,12 @@ void DivPlatformYM2610B::acquire(short* bufL, short* bufR, size_t start, size_t
void DivPlatformYM2610B::tick() { void DivPlatformYM2610B::tick() {
// PSG // PSG
for (int i=6; i<9; i++) { ay->tick();
chan[i].std.next(); ay->flushWrites();
if (chan[i].std.hadVol) { for (DivRegWrite& i: ay->getRegisterWrites()) {
chan[i].outVol=MIN(15,chan[i].std.vol)-(15-(chan[i].vol&15)); immWrite(i.addr&15,i.val);
if (chan[i].outVol<0) chan[i].outVol=0;
if (isMuted[i]) {
rWrite(0x02+i,0);
} else {
rWrite(0x02+i,(chan[i].outVol&15)|((chan[i].psgMode&4)<<2));
}
}
if (chan[i].std.hadArp) {
if (!chan[i].inPorta) {
if (chan[i].std.arpMode) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].std.arp);
} else {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note+chan[i].std.arp);
}
}
chan[i].freqChanged=true;
} else {
if (chan[i].std.arpMode && chan[i].std.finishedArp) {
chan[i].baseFreq=NOTE_PERIODIC(chan[i].note);
chan[i].freqChanged=true;
}
}
if (chan[i].std.hadDuty) {
ayNoiseFreq=31-chan[i].std.duty;
rWrite(0x06,ayNoiseFreq);
}
if (chan[i].std.hadWave) {
chan[i].psgMode=(chan[i].std.wave+1)&7;
if (isMuted[i]) {
rWrite(0x02+i,0);
} else {
rWrite(0x02+i,(chan[i].outVol&15)|((chan[i].psgMode&4)<<2));
}
}
if (chan[i].std.hadEx2) {
ayEnvMode=chan[i].std.ex2;
rWrite(0x0d,ayEnvMode);
}
if (chan[i].std.hadEx3) {
chan[i].autoEnvNum=chan[i].std.ex3;
chan[i].freqChanged=true;
if (!chan[i].std.willAlg) chan[i].autoEnvDen=1;
}
if (chan[i].std.hadAlg) {
chan[i].autoEnvDen=chan[i].std.alg;
chan[i].freqChanged=true;
if (!chan[i].std.willEx3) chan[i].autoEnvNum=1;
}
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true);
if (chan[i].freq>4095) chan[i].freq=4095;
if (chan[i].keyOn) {
}
if (chan[i].keyOff) {
rWrite(0x02+i,0);
}
rWrite((i-6)<<1,chan[i].freq&0xff);
rWrite(1+((i-6)<<1),chan[i].freq>>8);
if (chan[i].keyOn) chan[i].keyOn=false;
if (chan[i].keyOff) chan[i].keyOff=false;
if (chan[i].freqChanged && chan[i].autoEnvNum>0 && chan[i].autoEnvDen>0) {
ayEnvPeriod=(chan[i].freq*chan[i].autoEnvDen/chan[i].autoEnvNum)>>4;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
chan[i].freqChanged=false;
}
}
rWrite(0x07,
~((chan[6].psgMode&1)|
((chan[7].psgMode&1)<<1)|
((chan[8].psgMode&1)<<2)|
((chan[6].psgMode&2)<<2)|
((chan[7].psgMode&2)<<3)|
((chan[8].psgMode&2)<<4)));
if (ayEnvSlide!=0) {
ayEnvSlideLow+=ayEnvSlide;
while (ayEnvSlideLow>7) {
ayEnvSlideLow-=8;
if (ayEnvPeriod<0xffff) {
ayEnvPeriod++;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
}
while (ayEnvSlideLow<-7) {
ayEnvSlideLow+=8;
if (ayEnvPeriod>0) {
ayEnvPeriod--;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
}
}
} }
ay->getRegisterWrites().clear();
// FM // FM
for (int i=0; i<6; i++) { for (int i=0; i<6; i++) {
@ -683,7 +589,7 @@ void DivPlatformYM2610B::tick() {
chan[15].freqChanged=false; chan[15].freqChanged=false;
} }
for (int i=0; i<512; i++) { for (int i=16; i<512; i++) {
if (pendingWrites[i]!=oldWrites[i]) { if (pendingWrites[i]!=oldWrites[i]) {
immWrite(i,pendingWrites[i]&0xff); immWrite(i,pendingWrites[i]&0xff);
oldWrites[i]=pendingWrites[i]; oldWrites[i]=pendingWrites[i];
@ -749,6 +655,10 @@ int DivPlatformYM2610B::toFreq(int freq) {
} }
int DivPlatformYM2610B::dispatch(DivCommand c) { int DivPlatformYM2610B::dispatch(DivCommand c) {
if (c.chan>5 && c.chan<9) {
c.chan-=6;
return ay->dispatch(c);
}
switch (c.cmd) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
if (c.chan>14) { // ADPCM-B if (c.chan>14) { // ADPCM-B
@ -843,22 +753,6 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
} }
} }
if (c.chan>5) { // PSG
if (c.value!=DIV_NOTE_NULL) {
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value;
}
chan[c.chan].active=true;
chan[c.chan].keyOn=true;
if (isMuted[c.chan]) {
rWrite(0x02+c.chan,0);
} else {
rWrite(0x02+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
}
if (chan[c.chan].insChanged) { if (chan[c.chan].insChanged) {
chan[c.chan].state=ins->fm; chan[c.chan].state=ins->fm;
} }
@ -923,10 +817,6 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
immWrite(0x100,0x80|(1<<(c.chan-9))); immWrite(0x100,0x80|(1<<(c.chan-9)));
break; break;
} }
if (c.chan>5) {
chan[c.chan].std.release();
break;
}
chan[c.chan].keyOff=true; chan[c.chan].keyOff=true;
chan[c.chan].keyOn=false; chan[c.chan].keyOn=false;
chan[c.chan].active=false; chan[c.chan].active=false;
@ -948,14 +838,6 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
immWrite(0x108+(c.chan-9),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); immWrite(0x108+(c.chan-9),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol));
break; break;
} }
if (c.chan>5) { // PSG
if (isMuted[c.chan]) {
rWrite(0x02+c.chan,0);
} else {
if (chan[c.chan].active) rWrite(0x02+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
}
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i]; unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
DivInstrumentFM::Operator& op=chan[c.chan].state.op[i]; DivInstrumentFM::Operator& op=chan[c.chan].state.op[i];
@ -991,7 +873,6 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
immWrite(0x108+(c.chan-9),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol)); immWrite(0x108+(c.chan-9),isMuted[c.chan]?0:((chan[c.chan].pan<<6)|chan[c.chan].vol));
break; break;
} }
if (c.chan>5) break;
rWrite(chanOffs[c.chan]+ADDR_LRAF,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(chan[c.chan].state.fms&7)|((chan[c.chan].state.ams&3)<<4)); rWrite(chanOffs[c.chan]+ADDR_LRAF,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(chan[c.chan].state.fms&7)|((chan[c.chan].state.ams&3)<<4));
break; break;
} }
@ -1112,59 +993,6 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
} }
break; break;
} }
case DIV_CMD_STD_NOISE_MODE:
if (c.chan<6 || c.chan>8) break;
chan[c.chan].psgMode=(c.value+1)&7;
if (isMuted[c.chan]) {
rWrite(0x02+c.chan,0);
} else if (chan[c.chan].active) {
rWrite(0x02+c.chan,(chan[c.chan].outVol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
case DIV_CMD_STD_NOISE_FREQ:
if (c.chan<6 || c.chan>8) break;
ayNoiseFreq=31-c.value;
rWrite(0x06,ayNoiseFreq);
break;
case DIV_CMD_AY_ENVELOPE_SET:
if (c.chan<6 || c.chan>8) break;
ayEnvMode=c.value>>4;
rWrite(0x0d,ayEnvMode);
if (c.value&15) {
chan[c.chan].psgMode|=4;
} else {
chan[c.chan].psgMode&=~4;
}
if (isMuted[c.chan]) {
rWrite(0x02+c.chan,0);
} else {
rWrite(0x02+c.chan,(chan[c.chan].vol&15)|((chan[c.chan].psgMode&4)<<2));
}
break;
case DIV_CMD_AY_ENVELOPE_LOW:
if (c.chan<6 || c.chan>8) break;
ayEnvPeriod&=0xff00;
ayEnvPeriod|=c.value;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_HIGH:
if (c.chan<6 || c.chan>8) break;
ayEnvPeriod&=0xff;
ayEnvPeriod|=c.value<<8;
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8);
break;
case DIV_CMD_AY_ENVELOPE_SLIDE:
if (c.chan<6 || c.chan>8) break;
ayEnvSlide=c.value;
break;
case DIV_CMD_AY_AUTO_ENVELOPE:
if (c.chan<6 || c.chan>8) break;
chan[c.chan].autoEnvNum=c.value>>4;
chan[c.chan].autoEnvDen=c.value&15;
chan[c.chan].freqChanged=true;
break;
case DIV_ALWAYS_SET_VOLUME: case DIV_ALWAYS_SET_VOLUME:
return 0; return 0;
break; break;
@ -1201,11 +1029,7 @@ void DivPlatformYM2610B::muteChannel(int ch, bool mute) {
return; return;
} }
if (ch>5) { // PSG if (ch>5) { // PSG
if (isMuted[ch]) { ay->muteChannel(ch-6,mute);
rWrite(0x02+ch,0);
} else {
rWrite(0x02+ch,(chan[ch].outVol&15)|((chan[ch].psgMode&4)<<2));
}
return; return;
} }
// FM // FM
@ -1236,12 +1060,16 @@ void DivPlatformYM2610B::forceIns() {
chan[i].freqChanged=true; chan[i].freqChanged=true;
} }
} }
for (int i=6; i<16; i++) { for (int i=9; i<16; i++) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
immWrite(0x0b,ayEnvPeriod);
immWrite(0x0c,ayEnvPeriod>>8); ay->forceIns();
immWrite(0x0d,ayEnvMode); ay->flushWrites();
for (DivRegWrite& i: ay->getRegisterWrites()) {
immWrite(i.addr&15,i.val);
}
ay->getRegisterWrites().clear();
} }
void* DivPlatformYM2610B::getChanState(int ch) { void* DivPlatformYM2610B::getChanState(int ch) {
@ -1293,25 +1121,21 @@ void DivPlatformYM2610B::reset() {
lastBusy=60; lastBusy=60;
sampleBank=0; sampleBank=0;
ayEnvPeriod=0;
ayEnvMode=0;
ayEnvSlide=0;
ayEnvSlideLow=0;
ayNoiseFreq=0;
delay=0; delay=0;
extMode=false; extMode=false;
// AY noise
immWrite(0x06,ayNoiseFreq);
// LFO // LFO
immWrite(0x22,0x08); immWrite(0x22,0x08);
// PCM volume // PCM volume
immWrite(0x101,0x3f); // A immWrite(0x101,0x3f); // A
immWrite(0x1b,0xff); // B immWrite(0x1b,0xff); // B
ay->reset();
ay->getRegisterWrites().clear();
ay->flushWrites();
} }
bool DivPlatformYM2610B::isStereo() { bool DivPlatformYM2610B::isStereo() {
@ -1328,12 +1152,16 @@ void DivPlatformYM2610B::notifyInsChange(int ins) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
} }
ay->notifyInsChange(ins);
} }
void DivPlatformYM2610B::notifyInsDeletion(void* ins) { void DivPlatformYM2610B::notifyInsDeletion(void* ins) {
for (int i=6; i<9; i++) { ay->notifyInsDeletion(ins);
chan[i].std.notifyInsDeletion((DivInstrument*)ins); }
}
void DivPlatformYM2610B::setSkipRegisterWrites(bool value) {
DivDispatch::setSkipRegisterWrites(value);
ay->setSkipRegisterWrites(value);
} }
int DivPlatformYM2610B::init(DivEngine* p, int channels, int sugRate, unsigned int flags) { int DivPlatformYM2610B::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
@ -1348,11 +1176,17 @@ int DivPlatformYM2610B::init(DivEngine* p, int channels, int sugRate, unsigned i
iface.parent=parent; iface.parent=parent;
iface.sampleBank=0; iface.sampleBank=0;
fm=new ymfm::ym2610b(iface); fm=new ymfm::ym2610b(iface);
// YM2149, 2MHz
ay=new DivPlatformAY8910;
ay->init(p,3,sugRate,35);
ay->toggleRegisterDump(true);
reset(); reset();
return 16; return 16;
} }
void DivPlatformYM2610B::quit() { void DivPlatformYM2610B::quit() {
ay->quit();
delete ay;
delete fm; delete fm;
} }

View file

@ -82,7 +82,7 @@ class DivPlatformYM2610B: public DivDispatch {
unsigned char regPool[512]; unsigned char regPool[512];
unsigned char lastBusy; unsigned char lastBusy;
int ayNoiseFreq; DivPlatformAY8910* ay;
unsigned char sampleBank; unsigned char sampleBank;
int delay; int delay;
@ -91,10 +91,6 @@ class DivPlatformYM2610B: public DivDispatch {
short oldWrites[512]; short oldWrites[512];
short pendingWrites[512]; short pendingWrites[512];
unsigned char ayEnvMode;
unsigned short ayEnvPeriod;
short ayEnvSlideLow;
short ayEnvSlide;
int octave(int freq); int octave(int freq);
int toFreq(int freq); int toFreq(int freq);
@ -116,6 +112,7 @@ class DivPlatformYM2610B: public DivDispatch {
bool keyOffAffectsArp(int ch); bool keyOffAffectsArp(int ch);
void notifyInsChange(int ins); void notifyInsChange(int ins);
void notifyInsDeletion(void* ins); void notifyInsDeletion(void* ins);
void setSkipRegisterWrites(bool val);
void poke(unsigned int addr, unsigned short val); void poke(unsigned int addr, unsigned short val);
void poke(std::vector<DivRegWrite>& wlist); void poke(std::vector<DivRegWrite>& wlist);
const char** getRegisterSheet(); const char** getRegisterSheet();

View file

@ -316,9 +316,12 @@ void DivPlatformYM2610BExt::forceIns() {
for (int i=6; i<16; i++) { for (int i=6; i<16; i++) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
immWrite(0x0b,ayEnvPeriod); ay->forceIns();
immWrite(0x0c,ayEnvPeriod>>8); ay->flushWrites();
immWrite(0x0d,ayEnvMode); for (DivRegWrite& i: ay->getRegisterWrites()) {
immWrite(i.addr&15,i.val);
}
ay->getRegisterWrites().clear();
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
opChan[i].insChanged=true; opChan[i].insChanged=true;
if (opChan[i].active) { if (opChan[i].active) {

View file

@ -316,9 +316,12 @@ void DivPlatformYM2610Ext::forceIns() {
for (int i=4; i<14; i++) { for (int i=4; i<14; i++) {
chan[i].insChanged=true; chan[i].insChanged=true;
} }
immWrite(0x0b,ayEnvPeriod); ay->forceIns();
immWrite(0x0c,ayEnvPeriod>>8); ay->flushWrites();
immWrite(0x0d,ayEnvMode); for (DivRegWrite& i: ay->getRegisterWrites()) {
immWrite(i.addr&15,i.val);
}
ay->getRegisterWrites().clear();
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
opChan[i].insChanged=true; opChan[i].insChanged=true;
if (opChan[i].active) { if (opChan[i].active) {