From 0c5e58fa3e0f4328d534821ed9bd5e2a23c617b0 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 9 Jul 2023 15:12:45 -0500 Subject: [PATCH] YM2612: implement 9xxx, part 1 does not work on VGM export yet --- src/engine/dispatch.h | 3 +++ src/engine/platform/genesis.cpp | 15 ++++++++++++--- src/engine/platform/genesis.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index c458cf9c..acb7af66 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -288,6 +288,9 @@ struct DivRegWrite { * - x is the instance ID * - 0xffffxx04: switch sample bank * - for use in VGM export + * - 0xffffxx05: set sample position + * - xx is the instance ID + * - data is the sample position * - 0xffffffff: reset */ unsigned int addr; diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 1933a057..36284160 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -63,7 +63,7 @@ void DivPlatformGenesis::processDAC(int iRate) { for (int i=5; i<7; i++) { if (chan[i].dacSample!=-1) { DivSample* s=parent->getSample(chan[i].dacSample); - if (!isMuted[i] && s->samples>0) { + if (!isMuted[i] && s->samples>0 && chan[i].dacPossamples) { if (parent->song.noOPN2Vol) { chan[i].dacOutput=s->data8[chan[i].dacDirection?(s->samples-chan[i].dacPos-1):chan[i].dacPos]; } else { @@ -110,7 +110,7 @@ void DivPlatformGenesis::processDAC(int iRate) { chan[5].dacPeriod+=chan[5].dacRate; if (chan[5].dacPeriod>=iRate) { DivSample* s=parent->getSample(chan[5].dacSample); - if (s->samples>0) { + if (s->samples>0 && chan[5].dacPossamples) { if (!isMuted[5]) { if (chan[5].dacReady && writes.size()<16) { int sample; @@ -701,7 +701,11 @@ int DivPlatformGenesis::dispatch(DivCommand c) { addWrite(0xffff0003,chan[c.chan].dacDirection); } } - chan[c.chan].dacPos=0; + if (chan[c.chan].setPos) { + chan[c.chan].setPos=false; + } else { + chan[c.chan].dacPos=0; + } chan[c.chan].dacPeriod=0; if (c.value!=DIV_NOTE_NULL) { chan[c.chan].baseFreq=parent->calcBaseFreq(1,1,c.value,false); @@ -924,6 +928,11 @@ int DivPlatformGenesis::dispatch(DivCommand c) { if (dumpWrites) addWrite(0xffff0003,chan[c.chan].dacDirection); break; } + case DIV_CMD_SAMPLE_POS: + if (c.chan<5) c.chan=5; + chan[c.chan].dacPos=c.value; + chan[c.chan].setPos=true; + break; case DIV_CMD_LEGATO: { if (c.chan==csmChan) { chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index 210fca9d..c9de0493 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -57,6 +57,7 @@ class DivPlatformGenesis: public DivPlatformOPN { int dacDelay; bool dacReady; bool dacDirection; + bool setPos; unsigned char sampleBank; signed char dacOutput; Channel(): @@ -70,6 +71,7 @@ class DivPlatformGenesis: public DivPlatformOPN { dacDelay(0), dacReady(true), dacDirection(false), + setPos(false), sampleBank(0), dacOutput(0) {} };