WonderSwan: why does this not work

This commit is contained in:
tildearrow 2023-01-15 01:46:34 -05:00
parent 9ada18a57a
commit a3d20ac3fd
3 changed files with 17 additions and 8 deletions

View file

@ -22,6 +22,7 @@
#include <math.h> #include <math.h>
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);}} #define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);}}
#define postWrite(a,v) postDACWrites.emplace(a,v);
#define CHIP_DIVIDER 32 #define CHIP_DIVIDER 32
@ -186,7 +187,7 @@ void DivPlatformSwan::tick(bool sysTick) {
} }
} }
dacRate=((double)chipClock/2)/MAX(1,off*chan[i].freq); dacRate=((double)chipClock/2)/MAX(1,off*chan[i].freq);
if (dumpWrites) addWrite(0xffff0001,dacRate); if (dumpWrites) postWrite(0xffff0001,dacRate);
} }
if (chan[i].freq>2048) chan[i].freq=2048; if (chan[i].freq>2048) chan[i].freq=2048;
if (chan[i].freq<1) chan[i].freq=1; if (chan[i].freq<1) chan[i].freq=1;
@ -217,6 +218,12 @@ void DivPlatformSwan::tick(bool sysTick) {
} }
} }
rWrite(0x10,sndCtrl); rWrite(0x10,sndCtrl);
while (!postDACWrites.empty()) {
const DivRegWrite& w=postDACWrites.back();
if (dumpWrites) addWrite(w.addr,w.val);
postDACWrites.pop();
}
} }
int DivPlatformSwan::dispatch(DivCommand c) { int DivPlatformSwan::dispatch(DivCommand c) {
@ -237,11 +244,11 @@ int DivPlatformSwan::dispatch(DivCommand c) {
if (c.value!=DIV_NOTE_NULL) dacSample=ins->amiga.getSample(c.value); if (c.value!=DIV_NOTE_NULL) dacSample=ins->amiga.getSample(c.value);
if (dacSample<0 || dacSample>=parent->song.sampleLen) { if (dacSample<0 || dacSample>=parent->song.sampleLen) {
dacSample=-1; dacSample=-1;
if (dumpWrites) addWrite(0xffff0002,0); if (dumpWrites) postWrite(0xffff0002,0);
break; break;
} else { } else {
if (dumpWrites) { if (dumpWrites) {
addWrite(0xffff0000,dacSample); postWrite(0xffff0000,dacSample);
} }
} }
if (c.value!=DIV_NOTE_NULL) { if (c.value!=DIV_NOTE_NULL) {
@ -260,14 +267,14 @@ int DivPlatformSwan::dispatch(DivCommand c) {
dacSample=12*sampleBank+chan[1].note%12; dacSample=12*sampleBank+chan[1].note%12;
if (dacSample>=parent->song.sampleLen) { if (dacSample>=parent->song.sampleLen) {
dacSample=-1; dacSample=-1;
if (dumpWrites) addWrite(0xffff0002,0); if (dumpWrites) postWrite(0xffff0002,0);
break; break;
} else { } else {
if (dumpWrites) addWrite(0xffff0000,dacSample); if (dumpWrites) postWrite(0xffff0000,dacSample);
} }
dacRate=parent->getSample(dacSample)->rate; dacRate=parent->getSample(dacSample)->rate;
if (dumpWrites) { if (dumpWrites) {
addWrite(0xffff0001,dacRate); postWrite(0xffff0001,dacRate);
} }
chan[1].active=true; chan[1].active=true;
chan[1].keyOn=true; chan[1].keyOn=true;
@ -298,7 +305,7 @@ int DivPlatformSwan::dispatch(DivCommand c) {
case DIV_CMD_NOTE_OFF: case DIV_CMD_NOTE_OFF:
if (c.chan==1&&pcm) { if (c.chan==1&&pcm) {
dacSample=-1; dacSample=-1;
if (dumpWrites) addWrite(0xffff0002,0); if (dumpWrites) postWrite(0xffff0002,0);
pcm=false; pcm=false;
} }
chan[c.chan].active=false; chan[c.chan].active=false;
@ -463,6 +470,7 @@ int DivPlatformSwan::getRegisterPoolSize() {
void DivPlatformSwan::reset() { void DivPlatformSwan::reset() {
while (!writes.empty()) writes.pop(); while (!writes.empty()) writes.pop();
while (!postDACWrites.empty()) postDACWrites.pop();
memset(regPool,0,128); memset(regPool,0,128);
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
chan[i]=Channel(); chan[i]=Channel();

View file

@ -51,6 +51,7 @@ class DivPlatformSwan: public DivDispatch {
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {} QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {}
}; };
std::queue<QueuedWrite> writes; std::queue<QueuedWrite> writes;
std::queue<DivRegWrite> postDACWrites;
WSwan* ws; WSwan* ws;
void updateWave(int ch); void updateWave(int ch);
friend void putDispatchChip(void*,int); friend void putDispatchChip(void*,int);

View file

@ -570,7 +570,7 @@ void DivEngine::performVGMWrite(SafeWriter* w, DivSystem sys, DivRegWrite& write
w->writeC((sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)==0)|(sampleDir[streamID]?0x10:0)); // flags w->writeC((sample->getLoopStartPosition(DIV_SAMPLE_DEPTH_8BIT)==0)|(sampleDir[streamID]?0x10:0)); // flags
if (sample->isLoopable() && !sampleDir[streamID]) { if (sample->isLoopable() && !sampleDir[streamID]) {
loopTimer[streamID]=sample->length8; loopTimer[streamID]=sample->length8;
loopSample[streamID]=write.val; loopSample[streamID]=pendingFreq[streamID];
} }
playingSample[streamID]=pendingFreq[streamID]; playingSample[streamID]=pendingFreq[streamID];
pendingFreq[streamID]=-1; pendingFreq[streamID]=-1;