add reset() for every platform

This commit is contained in:
tildearrow 2021-12-11 13:14:38 -05:00
parent b0139015d0
commit a17e91955a
19 changed files with 157 additions and 98 deletions

View File

@ -340,16 +340,12 @@ int DivPlatformArcade::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformArcade::isStereo() {
return true;
}
int DivPlatformArcade::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
rate=447443;
void DivPlatformArcade::reset() {
while (!writes.empty()) writes.pop();
memset(&fm,0,sizeof(opm_t));
OPM_Reset(&fm);
for (int i=0; i<13; i++) {
chan[i]=DivPlatformArcade::Channel();
chan[i].vol=0x7f;
}
@ -367,6 +363,16 @@ int DivPlatformArcade::init(DivEngine* p, int channels, int sugRate, bool pal) {
rWrite(0x19,0xff);
extMode=false;
}
bool DivPlatformArcade::isStereo() {
return true;
}
int DivPlatformArcade::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
rate=447443;
reset();
return 13;
}

View File

@ -48,6 +48,7 @@ class DivPlatformArcade: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool isStereo();
int init(DivEngine* parent, int channels, int sugRate, bool pal);

View File

@ -279,6 +279,22 @@ int DivPlatformC64::dispatch(DivCommand c) {
return 1;
}
void DivPlatformC64::reset() {
for (int i=0; i<3; i++) {
chan[i]=DivPlatformC64::Channel();
}
sid.reset();
sid.write(0x18,0x0f);
filtControl=0;
filtRes=0;
filtCut=0;
resetTime=1;
vol=15;
}
void DivPlatformC64::setChipModel(bool is6581) {
if (is6581) {
sid.set_chip_model(MOS6581);
@ -295,15 +311,7 @@ int DivPlatformC64::init(DivEngine* p, int channels, int sugRate, bool pal) {
rate=1022727;
}
sid.reset();
sid.write(0x18,0x0f);
filtControl=0;
filtRes=0;
filtCut=0;
resetTime=1;
vol=15;
reset();
return 3;
}

View File

@ -55,6 +55,7 @@ class DivPlatformC64: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
int init(DivEngine* parent, int channels, int sugRate, bool pal);
void setChipModel(bool is6581);

View File

@ -61,12 +61,17 @@ int DivPlatformDummy::dispatch(DivCommand c) {
return 1;
}
void DivPlatformDummy::reset() {
for (int i=0; i<chans; i++) {
chan[i]=DivPlatformDummy::Channel();
chan[i].vol=0x0f;
}
}
int DivPlatformDummy::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
rate=65536;
chans=channels;
for (int i=0; i<chans; i++) {
chan[i].vol=0x0f;
}
reset();
return channels;
}

View File

@ -17,6 +17,7 @@ class DivPlatformDummy: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
int init(DivEngine* parent, int channels, int sugRate, bool pal);
};

View File

@ -270,14 +270,10 @@ int DivPlatformGB::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformGB::isStereo() {
return true;
void DivPlatformGB::reset() {
for (int i=0; i<4; i++) {
chan[i]=DivPlatformGB::Channel();
}
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
rate=262144;
gb=new GB_gameboy_t;
memset(gb,0,sizeof(GB_gameboy_t));
gb->model=GB_MODEL_DMG_B;
GB_apu_init(gb);
@ -286,5 +282,16 @@ int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, bool pal) {
GB_apu_write(gb,0x26,0x80);
GB_apu_write(gb,0x25,0xff);
lastPan=0xff;
}
bool DivPlatformGB::isStereo() {
return true;
}
int DivPlatformGB::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
rate=262144;
gb=new GB_gameboy_t;
reset();
return 4;
}

View File

@ -38,6 +38,7 @@ class DivPlatformGB: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool isStereo();
int init(DivEngine* parent, int channels, int sugRate, bool pal);

View File

@ -357,23 +357,11 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformGenesis::isStereo() {
return true;
}
bool DivPlatformGenesis::keyOffAffectsArp(int ch) {
return (ch>5);
}
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
if (pal) {
rate=211125;
} else {
rate=213068;
}
void DivPlatformGenesis::reset() {
while (!writes.empty()) writes.pop();
OPN2_Reset(&fm);
for (int i=0; i<10; i++) {
chan[i]=DivPlatformGenesis::Channel();
chan[i].vol=0x7f;
}
@ -398,8 +386,29 @@ int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate, bool pal)
delay=0;
// PSG
psg.init(p,4,sugRate,pal);
psg.reset();
psgClocks=0;
psgOut=0;
}
bool DivPlatformGenesis::isStereo() {
return true;
}
bool DivPlatformGenesis::keyOffAffectsArp(int ch) {
return (ch>5);
}
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
if (pal) {
rate=211125;
} else {
rate=213068;
}
// PSG
psg.init(p,4,sugRate,pal);
reset();
return 10;
}

View File

@ -51,6 +51,7 @@ class DivPlatformGenesis: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool isStereo();
bool keyOffAffectsArp(int ch);

View File

@ -254,6 +254,19 @@ void DivPlatformGenesisExt::tick() {
}
}
void DivPlatformGenesisExt::reset() {
DivPlatformGenesis::reset();
for (int i=0; i<4; i++) {
opChan[i]=DivPlatformGenesisExt::OpChannel();
opChan[i].vol=127;
}
// channel 3 mode
writes.emplace(0x27,0x40);
extMode=true;
}
bool DivPlatformGenesisExt::keyOffAffectsArp(int ch) {
return (ch>8);
}
@ -261,12 +274,6 @@ bool DivPlatformGenesisExt::keyOffAffectsArp(int ch) {
int DivPlatformGenesisExt::init(DivEngine* parent, int channels, int sugRate, bool pal) {
DivPlatformGenesis::init(parent,channels,sugRate,pal);
for (int i=0; i<4; i++) {
opChan[i].vol=127;
}
// channel 3 mode
writes.emplace(0x27,0x40);
extMode=true;
reset();
return 13;
}

View File

@ -16,6 +16,7 @@ class DivPlatformGenesisExt: public DivPlatformGenesis {
OpChannel opChan[4];
public:
int dispatch(DivCommand c);
void reset();
void tick();
bool keyOffAffectsArp(int ch);
int init(DivEngine* parent, int channels, int sugRate, bool pal);

View File

@ -252,12 +252,6 @@ int DivPlatformNES::dispatch(DivCommand c) {
sampleBank=parent->song.sample.size()/12;
}
break;
case DIV_CMD_PANNING: {
lastPan&=~(0x11<<c.chan);
if (c.value==0) c.value=0x11;
lastPan|=c.value<<c.chan;
break;
}
case DIV_CMD_LEGATO:
if (c.chan==3) break;
chan[c.chan].baseFreq=round(freqBase/pow(2.0f,((float)(c.value+((chan[c.chan].std.willArp && !chan[c.chan].std.arpMode)?(chan[c.chan].std.arp-12):(0)))/12.0f)));
@ -280,6 +274,26 @@ int DivPlatformNES::dispatch(DivCommand c) {
return 1;
}
void DivPlatformNES::reset() {
for (int i=0; i<5; i++) {
chan[i]=DivPlatformNES::Channel();
}
dacPeriod=0;
dacPos=0;
dacRate=0;
dacSample=-1;
sampleBank=0;
apu_turn_on();
apu.cpu_cycles=0;
apu.cpu_opcode_cycle=0;
apu_wr_reg(0x4015,0x1f);
apu_wr_reg(0x4001,0x08);
apu_wr_reg(0x4005,0x08);
}
bool DivPlatformNES::keyOffAffectsArp(int ch) {
return true;
}
@ -294,31 +308,9 @@ int DivPlatformNES::init(DivEngine* p, int channels, int sugRate, bool pal) {
freqBase=FREQ_BASE;
}
dacPeriod=0;
dacPos=0;
dacRate=0;
dacSample=-1;
sampleBank=0;
init_nla_table(500,500);
apu_turn_on();
apu.addrSpace=new unsigned char[65536];
apu.cpu_cycles=0;
apu.cpu_opcode_cycle=0;
apu_wr_reg(0x4015,0x1f);
apu_wr_reg(0x4001,0x08);
apu_wr_reg(0x4005,0x08);
/*apu_wr_reg(0x4000,0x3f);
apu_wr_reg(0x4001,0x00);
apu_wr_reg(0x4002,0xff);
apu_wr_reg(0x4003,0x10);
apu_wr_reg(0x4004,0x3f);
apu_wr_reg(0x4005,0x00);
apu_wr_reg(0x4006,0xfe);
apu_wr_reg(0x4007,0x10);*/
lastPan=0xff;
reset();
return 5;
}

View File

@ -41,6 +41,7 @@ class DivPlatformNES: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool keyOffAffectsArp(int ch);
int init(DivEngine* parent, int channels, int sugRate, bool pal);

View File

@ -263,23 +263,12 @@ int DivPlatformPCE::dispatch(DivCommand c) {
return 1;
}
bool DivPlatformPCE::isStereo() {
return true;
void DivPlatformPCE::reset() {
while (!writes.empty()) writes.pop();
for (int i=0; i<6; i++) {
chan[i]=DivPlatformPCE::Channel();
}
bool DivPlatformPCE::keyOffAffectsArp(int ch) {
return true;
}
int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
if (pal) { // technically there is no PAL PC Engine but oh well...
rate=1773448;
} else {
rate=1789773;
}
pce=new PCE_PSG(&tempL,&tempR,PCE_PSG::REVISION_HUC6280);
pce->Power(0);
lastPan=0xff;
tempL=0;
tempR=0;
@ -294,5 +283,24 @@ int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate, bool pal) {
chWrite(i,0x05,chan[i].pan);
}
delay=500;
}
bool DivPlatformPCE::isStereo() {
return true;
}
bool DivPlatformPCE::keyOffAffectsArp(int ch) {
return true;
}
int DivPlatformPCE::init(DivEngine* p, int channels, int sugRate, bool pal) {
parent=p;
if (pal) { // technically there is no PAL PC Engine but oh well...
rate=1773448;
} else {
rate=1789773;
}
pce=new PCE_PSG(&tempL,&tempR,PCE_PSG::REVISION_HUC6280);
reset();
return 6;
}

View File

@ -53,6 +53,7 @@ class DivPlatformPCE: public DivDispatch {
public:
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool isStereo();
bool keyOffAffectsArp(int ch);

View File

@ -159,6 +159,15 @@ int DivPlatformSMS::dispatch(DivCommand c) {
return 1;
}
void DivPlatformSMS::reset() {
for (int i=0; i<4; i++) {
chan[i]=DivPlatformSMS::Channel();
}
sn->device_start();
snNoiseMode=3;
updateSNMode=false;
}
bool DivPlatformSMS::keyOffAffectsArp(int ch) {
return true;
}
@ -171,8 +180,6 @@ int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate, bool pal) {
rate=223722;
}
sn=new sn76496_device(rate);
sn->device_start();
snNoiseMode=3;
updateSNMode=false;
reset();
return 4;
}

View File

@ -34,6 +34,7 @@ class DivPlatformSMS: public DivDispatch {
int acquireOne();
void acquire(short* bufL, short* bufR, size_t start, size_t len);
int dispatch(DivCommand c);
void reset();
void tick();
bool keyOffAffectsArp(int ch);
int init(DivEngine* parent, int channels, int sugRate, bool pal);

View File

@ -472,6 +472,7 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
}
void DivPlatformYM2610::reset() {
while (!writes.empty()) writes.pop();
fm->reset();
for (int i=0; i<13; i++) {
chan[i]=DivPlatformYM2610::Channel();