diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index b0cd80a2..82b66fc0 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -6,7 +6,7 @@ // TODO fix all the writes. // i think there is no wait for data writes, just for ON/OFF writes void DivPlatformGenesis::acquire(short& l, short& r) { - short o[2]; + static short o[2]; if (dacMode && dacSample!=-1) { if (--dacPeriod<1) { @@ -38,8 +38,16 @@ void DivPlatformGenesis::acquire(short& l, short& r) { } OPN2_Clock(&fm,o); //OPN2_Write(&fm,0,0); - l=o[0]<<7; - r=o[1]<<7; + + psgClocks+=223722; + if (psgClocks>=rate) { + psg.acquire(psgOut,psgOut); + psgClocks-=rate; + psgOut>>=2; + } + + l=(o[0]<<7)+psgOut; + r=(o[1]<<7)+psgOut; } static unsigned short chanOffs[6]={ @@ -122,12 +130,17 @@ void DivPlatformGenesis::tick() { chan[i].keyOn=false; } } + + psg.tick(); } #define rWrite(a,v) pendingWrites[a]=v; int DivPlatformGenesis::dispatch(DivCommand c) { - if (c.chan>5) return 0; + if (c.chan>5) { + c.chan-=6; + return psg.dispatch(c); + } switch (c.cmd) { case DIV_CMD_NOTE_ON: { if (c.chan==5 && dacMode) { @@ -313,5 +326,10 @@ int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) { writes.emplace(0x22,0x08); delay=0; + + // PSG + psg.init(p,4,sugRate); + psgClocks=0; + psgOut=0; return 10; } diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index f8d07988..d5c2c254 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -2,6 +2,8 @@ #include #include "../../../extern/Nuked-OPN2/ym3438.h" +#include "sms.h" + class DivPlatformGenesis: public DivDispatch { struct Channel { unsigned char freqH, freqL; @@ -22,6 +24,9 @@ class DivPlatformGenesis: public DivDispatch { }; std::queue writes; ym3438_t fm; + DivPlatformSMS psg; + int psgClocks; + short psgOut; int delay; unsigned char lastBusy; diff --git a/src/engine/platform/sms.cpp b/src/engine/platform/sms.cpp index 0570c291..af030eb3 100644 --- a/src/engine/platform/sms.cpp +++ b/src/engine/platform/sms.cpp @@ -56,6 +56,8 @@ int DivPlatformSMS::dispatch(DivCommand c) { break; case DIV_CMD_NOTE_OFF: chan[c.chan].active=false; + sn->write(0x9f|c.chan<<5); + chan[c.chan].std.init(NULL); break; case DIV_CMD_INSTRUMENT: chan[c.chan].ins=c.value; @@ -84,7 +86,7 @@ int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate) { rate=223722; sn=new sn76496_device("sn",223722); sn->device_start(); - snNoiseMode=0; + snNoiseMode=3; updateSNMode=false; return 4; } diff --git a/src/engine/platform/sms.h b/src/engine/platform/sms.h index c190fe67..393f4cb0 100644 --- a/src/engine/platform/sms.h +++ b/src/engine/platform/sms.h @@ -1,3 +1,6 @@ +#ifndef _SMS_H +#define _SMS_H + #include "../dispatch.h" #include "../macroInt.h" #include "sound/sn76496.h" @@ -21,3 +24,5 @@ class DivPlatformSMS: public DivDispatch { void tick(); int init(DivEngine* parent, int channels, int sugRate); }; + +#endif