bind SMS platform to Genesis one

This commit is contained in:
tildearrow 2021-05-15 16:59:57 -05:00
parent 3172fd37ed
commit f2c70df4a8
4 changed files with 35 additions and 5 deletions

View File

@ -6,7 +6,7 @@
// TODO fix all the writes. // TODO fix all the writes.
// i think there is no wait for data writes, just for ON/OFF writes // i think there is no wait for data writes, just for ON/OFF writes
void DivPlatformGenesis::acquire(short& l, short& r) { void DivPlatformGenesis::acquire(short& l, short& r) {
short o[2]; static short o[2];
if (dacMode && dacSample!=-1) { if (dacMode && dacSample!=-1) {
if (--dacPeriod<1) { if (--dacPeriod<1) {
@ -38,8 +38,16 @@ void DivPlatformGenesis::acquire(short& l, short& r) {
} }
OPN2_Clock(&fm,o); OPN2_Clock(&fm,o);
//OPN2_Write(&fm,0,0); //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]={ static unsigned short chanOffs[6]={
@ -122,12 +130,17 @@ void DivPlatformGenesis::tick() {
chan[i].keyOn=false; chan[i].keyOn=false;
} }
} }
psg.tick();
} }
#define rWrite(a,v) pendingWrites[a]=v; #define rWrite(a,v) pendingWrites[a]=v;
int DivPlatformGenesis::dispatch(DivCommand c) { 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) { switch (c.cmd) {
case DIV_CMD_NOTE_ON: { case DIV_CMD_NOTE_ON: {
if (c.chan==5 && dacMode) { if (c.chan==5 && dacMode) {
@ -313,5 +326,10 @@ int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate) {
writes.emplace(0x22,0x08); writes.emplace(0x22,0x08);
delay=0; delay=0;
// PSG
psg.init(p,4,sugRate);
psgClocks=0;
psgOut=0;
return 10; return 10;
} }

View File

@ -2,6 +2,8 @@
#include <queue> #include <queue>
#include "../../../extern/Nuked-OPN2/ym3438.h" #include "../../../extern/Nuked-OPN2/ym3438.h"
#include "sms.h"
class DivPlatformGenesis: public DivDispatch { class DivPlatformGenesis: public DivDispatch {
struct Channel { struct Channel {
unsigned char freqH, freqL; unsigned char freqH, freqL;
@ -22,6 +24,9 @@ class DivPlatformGenesis: public DivDispatch {
}; };
std::queue<QueuedWrite> writes; std::queue<QueuedWrite> writes;
ym3438_t fm; ym3438_t fm;
DivPlatformSMS psg;
int psgClocks;
short psgOut;
int delay; int delay;
unsigned char lastBusy; unsigned char lastBusy;

View File

@ -56,6 +56,8 @@ int DivPlatformSMS::dispatch(DivCommand c) {
break; break;
case DIV_CMD_NOTE_OFF: case DIV_CMD_NOTE_OFF:
chan[c.chan].active=false; chan[c.chan].active=false;
sn->write(0x9f|c.chan<<5);
chan[c.chan].std.init(NULL);
break; break;
case DIV_CMD_INSTRUMENT: case DIV_CMD_INSTRUMENT:
chan[c.chan].ins=c.value; chan[c.chan].ins=c.value;
@ -84,7 +86,7 @@ int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate) {
rate=223722; rate=223722;
sn=new sn76496_device("sn",223722); sn=new sn76496_device("sn",223722);
sn->device_start(); sn->device_start();
snNoiseMode=0; snNoiseMode=3;
updateSNMode=false; updateSNMode=false;
return 4; return 4;
} }

View File

@ -1,3 +1,6 @@
#ifndef _SMS_H
#define _SMS_H
#include "../dispatch.h" #include "../dispatch.h"
#include "../macroInt.h" #include "../macroInt.h"
#include "sound/sn76496.h" #include "sound/sn76496.h"
@ -21,3 +24,5 @@ class DivPlatformSMS: public DivDispatch {
void tick(); void tick();
int init(DivEngine* parent, int channels, int sugRate); int init(DivEngine* parent, int channels, int sugRate);
}; };
#endif