more SMS work
it is able to play some modules... the next step is to bind this to the Genesis platform
This commit is contained in:
parent
d9f076ef64
commit
3172fd37ed
7 changed files with 147 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
#include "sms.h"
|
||||
#include "../engine.h"
|
||||
#include <math.h>
|
||||
|
||||
void DivPlatformSMS::acquire(short& l, short& r) {
|
||||
|
|
@ -9,8 +10,13 @@ void DivPlatformSMS::acquire(short& l, short& r) {
|
|||
}
|
||||
|
||||
void DivPlatformSMS::tick() {
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].std.next();
|
||||
if (chan[i].std.hadVol) sn->write(0x90|(i<<5)|(15-((chan[i].vol*chan[i].std.vol)>>4)));
|
||||
}
|
||||
for (int i=0; i<3; i++) {
|
||||
if (chan[i].freqChanged) {
|
||||
chan[i].freq=(chan[i].baseFreq*(2048-chan[i].pitch))>>11;
|
||||
sn->write(0x80|i<<5|(chan[i].freq&15));
|
||||
sn->write(chan[i].freq>>4);
|
||||
chan[i].freqChanged=false;
|
||||
|
|
@ -18,6 +24,7 @@ void DivPlatformSMS::tick() {
|
|||
}
|
||||
if (chan[3].freqChanged || updateSNMode) {
|
||||
updateSNMode=false;
|
||||
chan[3].freq=(chan[3].baseFreq*(2048-chan[3].pitch))>>11;
|
||||
chan[3].freqChanged=false;
|
||||
if (snNoiseMode&2) { // take period from channel 3
|
||||
if (snNoiseMode&1) {
|
||||
|
|
@ -40,19 +47,28 @@ void DivPlatformSMS::tick() {
|
|||
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].baseFreq=1712/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));
|
||||
chan[c.chan].std.init(parent->song.ins[chan[c.chan].ins]);
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF:
|
||||
chan[c.chan].active=false;
|
||||
break;
|
||||
case DIV_CMD_INSTRUMENT:
|
||||
chan[c.chan].ins=c.value;
|
||||
chan[c.chan].std.init(parent->song.ins[chan[c.chan].ins]);
|
||||
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_PITCH:
|
||||
chan[c.chan].pitch=c.value;
|
||||
chan[c.chan].freqChanged=true;
|
||||
break;
|
||||
case DIV_CMD_STD_NOISE_MODE:
|
||||
snNoiseMode=(c.value&1)|((c.value&16)>>3);
|
||||
updateSNMode=true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "../dispatch.h"
|
||||
#include "../macroInt.h"
|
||||
#include "sound/sn76496.h"
|
||||
|
||||
class DivPlatformSMS: public DivDispatch {
|
||||
|
|
@ -7,6 +8,7 @@ class DivPlatformSMS: public DivDispatch {
|
|||
unsigned char ins, note;
|
||||
bool active, insChanged, freqChanged, keyOn, keyOff;
|
||||
signed char vol;
|
||||
DivMacroInt std;
|
||||
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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue