prepare to add SMS platform

plays but no macro yet
This commit is contained in:
tildearrow 2021-05-15 14:18:16 -05:00
parent 9a97c38cc6
commit d9f076ef64
6 changed files with 110 additions and 1 deletions

View file

@ -33,6 +33,7 @@ src/engine/engine.cpp
src/engine/playback.cpp src/engine/playback.cpp
src/engine/platform/abstract.cpp src/engine/platform/abstract.cpp
src/engine/platform/genesis.cpp src/engine/platform/genesis.cpp
src/engine/platform/sms.cpp
src/engine/platform/dummy.cpp) src/engine/platform/dummy.cpp)
#imgui/imgui.cpp #imgui/imgui.cpp

View file

@ -3,6 +3,7 @@
#include "../ta-log.h" #include "../ta-log.h"
#include "../audio/sdl.h" #include "../audio/sdl.h"
#include "platform/genesis.h" #include "platform/genesis.h"
#include "platform/sms.h"
#include "platform/dummy.h" #include "platform/dummy.h"
#include <math.h> #include <math.h>
#include <zlib.h> #include <zlib.h>
@ -671,6 +672,9 @@ bool DivEngine::init() {
case DIV_SYSTEM_GENESIS: case DIV_SYSTEM_GENESIS:
dispatch=new DivPlatformGenesis; dispatch=new DivPlatformGenesis;
break; break;
case DIV_SYSTEM_SMS:
dispatch=new DivPlatformSMS;
break;
default: default:
dispatch=new DivPlatformDummy; dispatch=new DivPlatformDummy;
break; break;

View file

@ -0,0 +1,74 @@
#include "sms.h"
#include <math.h>
void DivPlatformSMS::acquire(short& l, short& r) {
short v;
sn->sound_stream_update(&v,1);
l=v;
r=v;
}
void DivPlatformSMS::tick() {
for (int i=0; i<3; i++) {
if (chan[i].freqChanged) {
sn->write(0x80|i<<5|(chan[i].freq&15));
sn->write(chan[i].freq>>4);
chan[i].freqChanged=false;
}
}
if (chan[3].freqChanged || updateSNMode) {
updateSNMode=false;
chan[3].freqChanged=false;
if (snNoiseMode&2) { // take period from channel 3
if (snNoiseMode&1) {
sn->write(0xe7);
} else {
sn->write(0xe3);
}
sn->write(0xdf);
sn->write(0xc0|(chan[3].freq&15));
sn->write(chan[3].freq>>4);
} else { // 3 fixed values
unsigned char value=chan[3].note%12;
if (value>2) value=2;
value=2-value;
sn->write(0xe0|value|((snNoiseMode&1)<<2));
}
}
}
int DivPlatformSMS::dispatch(DivCommand c) {
switch (c.cmd) {
case DIV_CMD_NOTE_ON:
chan[c.chan].freq=3430/pow(2.0f,((float)c.value/12.0f));
chan[c.chan].freqChanged=true;
chan[c.chan].note=c.value;
chan[c.chan].active=true;
sn->write(0x90|c.chan<<5|(15-chan[c.chan].vol));
break;
case DIV_CMD_NOTE_OFF:
chan[c.chan].active=false;
break;
case DIV_CMD_VOLUME:
chan[c.chan].vol=c.value;
sn->write(0x90|c.chan<<5|(15-chan[c.chan].vol));
break;
case DIV_CMD_STD_NOISE_MODE:
snNoiseMode=(c.value&1)|((c.value&16)>>3);
updateSNMode=true;
break;
default:
break;
}
return 1;
}
int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate) {
parent=p;
rate=223722;
sn=new sn76496_device("sn",223722);
sn->device_start();
snNoiseMode=0;
updateSNMode=false;
return 4;
}

21
src/engine/platform/sms.h Normal file
View file

@ -0,0 +1,21 @@
#include "../dispatch.h"
#include "sound/sn76496.h"
class DivPlatformSMS: public DivDispatch {
struct Channel {
int freq, baseFreq, pitch;
unsigned char ins, note;
bool active, insChanged, freqChanged, keyOn, keyOff;
signed char vol;
Channel(): freq(0), baseFreq(0), pitch(0), ins(0), note(0), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), vol(15) {}
};
Channel chan[4];
unsigned char snNoiseMode;
bool updateSNMode;
sn76496_device* sn;
public:
void acquire(short& l, short& r);
int dispatch(DivCommand c);
void tick();
int init(DivEngine* parent, int channels, int sugRate);
};

View file

@ -165,7 +165,7 @@ sn76496_base_device::sn76496_base_device(
} }
sn76496_device::sn76496_device(const char *tag, uint32_t clock) sn76496_device::sn76496_device(const char *tag, uint32_t clock)
: sn76496_base_device(tag, 0x10000, 0x04, 0x08, false, 8, false, true, clock) : sn76496_base_device(tag, 0x8000, 0x01, 0x08, true, 1, false, false, clock)
{ {
} }

View file

@ -33,6 +33,15 @@ bool DivEngine::perSystemEffect(int ch, unsigned char effect, unsigned char effe
return false; return false;
} }
break; break;
case DIV_SYSTEM_SMS:
switch (effect) {
case 0x20: // SN noise mode
dispatch->dispatch(DivCommand(DIV_CMD_STD_NOISE_MODE,ch,effectVal));
break;
default:
return false;
}
break;
default: default:
return false; return false;
} }