2021-05-12 22:19:18 +00:00
|
|
|
#include "genesis.h"
|
|
|
|
#include "../engine.h"
|
|
|
|
#include <string.h>
|
2021-05-14 08:23:40 +00:00
|
|
|
#include <math.h>
|
2021-05-12 22:19:18 +00:00
|
|
|
|
2021-05-18 21:02:49 +00:00
|
|
|
#include "genesisshared.h"
|
|
|
|
|
2021-05-28 04:03:10 +00:00
|
|
|
static unsigned char konOffs[6]={
|
|
|
|
0, 1, 2, 4, 5, 6
|
|
|
|
};
|
|
|
|
|
2021-12-06 21:51:18 +00:00
|
|
|
void DivPlatformGenesis::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
2021-05-15 21:59:57 +00:00
|
|
|
static short o[2];
|
2021-06-09 06:57:12 +00:00
|
|
|
static int os[2];
|
2021-05-13 07:39:26 +00:00
|
|
|
|
2021-12-06 10:21:42 +00:00
|
|
|
for (size_t h=start; h<start+len; h++) {
|
|
|
|
if (dacMode && dacSample!=-1) {
|
|
|
|
dacPeriod-=6;
|
|
|
|
if (dacPeriod<1) {
|
|
|
|
DivSample* s=parent->song.sample[dacSample];
|
2021-12-19 05:51:10 +00:00
|
|
|
if (!isMuted[5]) {
|
|
|
|
if (s->depth==8) {
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(0x2a,(unsigned char)s->rendData[dacPos++]+0x80);
|
2021-12-19 05:51:10 +00:00
|
|
|
} else {
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(0x2a,((unsigned short)s->rendData[dacPos++]+0x8000)>>8);
|
2021-12-19 05:51:10 +00:00
|
|
|
}
|
2021-12-06 10:21:42 +00:00
|
|
|
}
|
|
|
|
if (dacPos>=s->rendLength) {
|
|
|
|
dacSample=-1;
|
|
|
|
}
|
|
|
|
dacPeriod+=dacRate;
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-06 10:21:42 +00:00
|
|
|
|
|
|
|
os[0]=0; os[1]=0;
|
|
|
|
for (int i=0; i<6; i++) {
|
|
|
|
if (!writes.empty() && --delay<0) {
|
|
|
|
delay=0;
|
|
|
|
QueuedWrite& w=writes.front();
|
|
|
|
if (w.addrOrVal) {
|
|
|
|
OPN2_Write(&fm,0x1+((w.addr>>8)<<1),w.val);
|
|
|
|
//printf("write: %x = %.2x\n",w.addr,w.val);
|
|
|
|
lastBusy=0;
|
|
|
|
writes.pop();
|
|
|
|
} else {
|
|
|
|
lastBusy++;
|
|
|
|
if (fm.write_busy==0) {
|
|
|
|
//printf("busycounter: %d\n",lastBusy);
|
|
|
|
OPN2_Write(&fm,0x0+((w.addr>>8)<<1),w.addr);
|
|
|
|
w.addrOrVal=true;
|
|
|
|
}
|
2021-12-06 08:07:29 +00:00
|
|
|
}
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
2021-12-06 10:21:42 +00:00
|
|
|
|
|
|
|
OPN2_Clock(&fm,o); os[0]+=o[0]; os[1]+=o[1];
|
|
|
|
//OPN2_Write(&fm,0,0);
|
|
|
|
}
|
2021-12-06 08:07:29 +00:00
|
|
|
|
2021-12-08 06:56:40 +00:00
|
|
|
psgClocks+=psg.rate;
|
2021-12-06 10:21:42 +00:00
|
|
|
while (psgClocks>=rate) {
|
|
|
|
psgOut=(psg.acquireOne()*3)>>3;
|
|
|
|
psgClocks-=rate;
|
|
|
|
}
|
2021-12-08 06:56:40 +00:00
|
|
|
|
|
|
|
os[0]=(os[0]<<5)+psgOut;
|
|
|
|
if (os[0]<-32768) os[0]=-32768;
|
|
|
|
if (os[0]>32767) os[0]=32767;
|
|
|
|
|
|
|
|
os[1]=(os[1]<<5)+psgOut;
|
|
|
|
if (os[1]<-32768) os[1]=-32768;
|
|
|
|
if (os[1]>32767) os[1]=32767;
|
2021-05-15 21:59:57 +00:00
|
|
|
|
2021-12-08 06:56:40 +00:00
|
|
|
bufL[h]=os[0];
|
|
|
|
bufR[h]=os[1];
|
2021-05-15 21:59:57 +00:00
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
}
|
|
|
|
|
2021-05-13 08:09:56 +00:00
|
|
|
void DivPlatformGenesis::tick() {
|
|
|
|
for (int i=0; i<6; i++) {
|
2021-05-18 21:02:49 +00:00
|
|
|
if (i==2 && extMode) continue;
|
2021-05-13 08:18:54 +00:00
|
|
|
if (chan[i].keyOn || chan[i].keyOff) {
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(0x28,0x00|konOffs[i]);
|
2021-05-13 08:18:54 +00:00
|
|
|
chan[i].keyOff=false;
|
2021-05-13 08:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<512; i++) {
|
2021-05-16 08:03:23 +00:00
|
|
|
if (pendingWrites[i]!=oldWrites[i]) {
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(i,pendingWrites[i]&0xff);
|
2021-05-16 08:03:23 +00:00
|
|
|
oldWrites[i]=pendingWrites[i];
|
2021-05-13 08:09:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<6; i++) {
|
2021-05-18 21:02:49 +00:00
|
|
|
if (i==2 && extMode) continue;
|
2021-05-14 08:23:40 +00:00
|
|
|
if (chan[i].freqChanged) {
|
2021-12-28 05:51:38 +00:00
|
|
|
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch);
|
2021-05-19 19:39:39 +00:00
|
|
|
int freqt=toFreq(chan[i].freq);
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(chanOffs[i]+0xa4,freqt>>8);
|
|
|
|
immWrite(chanOffs[i]+0xa0,freqt&0xff);
|
2021-12-11 21:44:02 +00:00
|
|
|
chan[i].freqChanged=false;
|
2021-05-14 08:23:40 +00:00
|
|
|
}
|
|
|
|
if (chan[i].keyOn) {
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(0x28,0xf0|konOffs[i]);
|
2021-05-13 08:09:56 +00:00
|
|
|
chan[i].keyOn=false;
|
|
|
|
}
|
|
|
|
}
|
2021-05-15 21:59:57 +00:00
|
|
|
|
|
|
|
psg.tick();
|
2021-05-13 08:09:56 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 06:20:38 +00:00
|
|
|
int DivPlatformGenesis::octave(int freq) {
|
|
|
|
if (freq>=82432) {
|
|
|
|
return 128;
|
|
|
|
} else if (freq>=41216) {
|
|
|
|
return 64;
|
|
|
|
} else if (freq>=20608) {
|
|
|
|
return 32;
|
|
|
|
} else if (freq>=10304) {
|
|
|
|
return 16;
|
|
|
|
} else if (freq>=5152) {
|
|
|
|
return 8;
|
|
|
|
} else if (freq>=2576) {
|
|
|
|
return 4;
|
|
|
|
} else if (freq>=1288) {
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-05-19 19:39:39 +00:00
|
|
|
int DivPlatformGenesis::toFreq(int freq) {
|
|
|
|
if (freq>=82432) {
|
|
|
|
return 0x3800|((freq>>7)&0x7ff);
|
|
|
|
} else if (freq>=41216) {
|
|
|
|
return 0x3000|((freq>>6)&0x7ff);
|
|
|
|
} else if (freq>=20608) {
|
|
|
|
return 0x2800|((freq>>5)&0x7ff);
|
|
|
|
} else if (freq>=10304) {
|
|
|
|
return 0x2000|((freq>>4)&0x7ff);
|
|
|
|
} else if (freq>=5152) {
|
|
|
|
return 0x1800|((freq>>3)&0x7ff);
|
|
|
|
} else if (freq>=2576) {
|
|
|
|
return 0x1000|((freq>>2)&0x7ff);
|
|
|
|
} else if (freq>=1288) {
|
|
|
|
return 0x800|((freq>>1)&0x7ff);
|
|
|
|
} else {
|
|
|
|
return freq&0x7ff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-18 08:25:42 +00:00
|
|
|
void DivPlatformGenesis::muteChannel(int ch, bool mute) {
|
|
|
|
if (ch>5) {
|
2021-12-19 05:49:47 +00:00
|
|
|
psg.muteChannel(ch-6,mute);
|
2021-12-18 08:25:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
isMuted[ch]=mute;
|
|
|
|
DivInstrument* ins=parent->getIns(chan[ch].ins);
|
|
|
|
rWrite(chanOffs[ch]+0xb4,(isMuted[ch]?0:(chan[ch].pan<<6))|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
|
|
|
}
|
|
|
|
|
2021-05-12 22:19:18 +00:00
|
|
|
int DivPlatformGenesis::dispatch(DivCommand c) {
|
2021-05-15 21:59:57 +00:00
|
|
|
if (c.chan>5) {
|
|
|
|
c.chan-=6;
|
|
|
|
return psg.dispatch(c);
|
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
switch (c.cmd) {
|
|
|
|
case DIV_CMD_NOTE_ON: {
|
2021-05-13 07:39:26 +00:00
|
|
|
if (c.chan==5 && dacMode) {
|
2021-12-21 06:29:07 +00:00
|
|
|
if (skipRegisterWrites) break;
|
2021-12-09 08:13:37 +00:00
|
|
|
dacSample=12*sampleBank+c.value%12;
|
2021-05-13 07:39:26 +00:00
|
|
|
if (dacSample>=parent->song.sampleLen) {
|
|
|
|
dacSample=-1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dacPos=0;
|
|
|
|
dacPeriod=0;
|
2021-12-23 23:04:44 +00:00
|
|
|
dacRate=1280000/parent->song.sample[dacSample]->rate;
|
2021-05-13 07:39:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-05-13 08:09:56 +00:00
|
|
|
|
2021-05-17 08:06:45 +00:00
|
|
|
|
2021-05-16 08:03:23 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
|
|
|
DivInstrumentFM::Operator op=ins->fm.op[i];
|
|
|
|
if (isOutput[ins->fm.alg][i]) {
|
2021-05-18 05:43:00 +00:00
|
|
|
if (!chan[c.chan].active || chan[c.chan].insChanged) {
|
2021-05-17 21:32:56 +00:00
|
|
|
rWrite(baseAddr+0x40,127-(((127-op.tl)*(chan[c.chan].vol&0x7f))/127));
|
|
|
|
}
|
2021-05-16 08:03:23 +00:00
|
|
|
} else {
|
2021-05-17 08:06:45 +00:00
|
|
|
if (chan[c.chan].insChanged) {
|
|
|
|
rWrite(baseAddr+0x40,op.tl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[c.chan].insChanged) {
|
|
|
|
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
|
|
|
rWrite(baseAddr+0x50,(op.ar&31)|(op.rs<<6));
|
|
|
|
rWrite(baseAddr+0x60,(op.dr&31)|(op.am<<7));
|
|
|
|
rWrite(baseAddr+0x70,op.d2r&31);
|
|
|
|
rWrite(baseAddr+0x80,(op.rr&15)|(op.sl<<4));
|
|
|
|
rWrite(baseAddr+0x90,op.ssgEnv&15);
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
}
|
2021-05-17 08:06:45 +00:00
|
|
|
if (chan[c.chan].insChanged) {
|
|
|
|
rWrite(chanOffs[c.chan]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
2021-12-18 08:25:42 +00:00
|
|
|
rWrite(chanOffs[c.chan]+0xb4,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
2021-05-17 08:06:45 +00:00
|
|
|
}
|
|
|
|
chan[c.chan].insChanged=false;
|
|
|
|
|
2022-01-19 05:01:34 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
|
|
|
chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f));
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
}
|
2021-05-13 08:09:56 +00:00
|
|
|
chan[c.chan].keyOn=true;
|
2021-05-12 22:19:18 +00:00
|
|
|
chan[c.chan].active=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_OFF:
|
2021-12-09 08:25:00 +00:00
|
|
|
if (c.chan==5) {
|
|
|
|
dacSample=-1;
|
|
|
|
}
|
2021-05-13 08:18:54 +00:00
|
|
|
chan[c.chan].keyOff=true;
|
2021-05-12 22:19:18 +00:00
|
|
|
chan[c.chan].active=false;
|
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
case DIV_CMD_VOLUME: {
|
2021-05-12 22:19:18 +00:00
|
|
|
chan[c.chan].vol=c.value;
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-05-13 07:39:26 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
|
|
|
DivInstrumentFM::Operator op=ins->fm.op[i];
|
|
|
|
if (isOutput[ins->fm.alg][i]) {
|
2021-05-17 20:51:12 +00:00
|
|
|
rWrite(baseAddr+0x40,127-(((127-op.tl)*(chan[c.chan].vol&0x7f))/127));
|
2021-05-13 07:39:26 +00:00
|
|
|
} else {
|
2021-05-13 08:09:56 +00:00
|
|
|
rWrite(baseAddr+0x40,op.tl);
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
2021-05-17 08:06:45 +00:00
|
|
|
case DIV_CMD_GET_VOLUME: {
|
|
|
|
return chan[c.chan].vol;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
case DIV_CMD_INSTRUMENT:
|
2022-01-17 23:01:40 +00:00
|
|
|
if (chan[c.chan].ins!=c.value || c.value2==1) {
|
2021-05-13 07:39:26 +00:00
|
|
|
chan[c.chan].insChanged=true;
|
|
|
|
}
|
2021-05-12 22:19:18 +00:00
|
|
|
chan[c.chan].ins=c.value;
|
|
|
|
break;
|
2021-05-13 07:39:26 +00:00
|
|
|
case DIV_CMD_PANNING: {
|
|
|
|
switch (c.value) {
|
|
|
|
case 0x01:
|
|
|
|
chan[c.chan].pan=1;
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
chan[c.chan].pan=2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
chan[c.chan].pan=3;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-12-18 08:25:42 +00:00
|
|
|
rWrite(chanOffs[c.chan]+0xb4,(isMuted[c.chan]?0:(chan[c.chan].pan<<6))|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
2021-05-13 07:39:26 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-05-14 19:16:48 +00:00
|
|
|
case DIV_CMD_PITCH: {
|
|
|
|
chan[c.chan].pitch=c.value;
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_PORTA: {
|
|
|
|
int destFreq=644.0f*pow(2.0f,((float)c.value2/12.0f));
|
2021-05-19 19:39:39 +00:00
|
|
|
int newFreq;
|
2021-05-14 19:16:48 +00:00
|
|
|
bool return2=false;
|
|
|
|
if (destFreq>chan[c.chan].baseFreq) {
|
2021-05-19 19:39:39 +00:00
|
|
|
newFreq=chan[c.chan].baseFreq+c.value*octave(chan[c.chan].baseFreq);
|
|
|
|
if (newFreq>=destFreq) {
|
|
|
|
newFreq=destFreq;
|
2021-05-14 19:16:48 +00:00
|
|
|
return2=true;
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-19 19:39:39 +00:00
|
|
|
newFreq=chan[c.chan].baseFreq-c.value*octave(chan[c.chan].baseFreq);
|
|
|
|
if (newFreq<=destFreq) {
|
|
|
|
newFreq=destFreq;
|
2021-05-14 19:16:48 +00:00
|
|
|
return2=true;
|
|
|
|
}
|
|
|
|
}
|
2021-05-19 19:39:39 +00:00
|
|
|
if (!chan[c.chan].portaPause) {
|
|
|
|
if (octave(chan[c.chan].baseFreq)!=octave(newFreq)) {
|
|
|
|
chan[c.chan].portaPause=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
chan[c.chan].baseFreq=newFreq;
|
|
|
|
chan[c.chan].portaPause=false;
|
2021-05-14 19:16:48 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
if (return2) return 2;
|
|
|
|
break;
|
|
|
|
}
|
2021-05-13 07:39:26 +00:00
|
|
|
case DIV_CMD_SAMPLE_MODE: {
|
|
|
|
if (c.chan==5) {
|
|
|
|
dacMode=c.value;
|
2021-05-13 08:09:56 +00:00
|
|
|
rWrite(0x2b,c.value<<7);
|
2021-05-13 07:39:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-12-09 08:13:37 +00:00
|
|
|
case DIV_CMD_SAMPLE_BANK:
|
|
|
|
sampleBank=c.value;
|
|
|
|
if (sampleBank>(parent->song.sample.size()/12)) {
|
|
|
|
sampleBank=parent->song.sample.size()/12;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 08:13:21 +00:00
|
|
|
case DIV_CMD_LEGATO: {
|
|
|
|
chan[c.chan].baseFreq=644.0f*pow(2.0f,((float)c.value/12.0f));
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
|
|
|
}
|
2021-06-06 04:27:02 +00:00
|
|
|
case DIV_CMD_FM_LFO: {
|
|
|
|
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
|
|
|
break;
|
|
|
|
}
|
2021-05-15 08:13:21 +00:00
|
|
|
case DIV_CMD_FM_MULT: {
|
2021-05-17 08:06:45 +00:00
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]];
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-05-17 08:06:45 +00:00
|
|
|
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
2021-05-15 08:13:21 +00:00
|
|
|
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_FM_TL: {
|
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]];
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-05-15 08:13:21 +00:00
|
|
|
if (isOutput[ins->fm.alg][c.value]) {
|
2021-05-17 20:51:12 +00:00
|
|
|
rWrite(baseAddr+0x40,127-(((127-c.value2)*(chan[c.chan].vol&0x7f))/127));
|
2021-05-15 08:13:21 +00:00
|
|
|
} else {
|
|
|
|
rWrite(baseAddr+0x40,c.value2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_FM_AR: {
|
2021-05-17 01:49:54 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins);
|
2021-05-15 08:13:21 +00:00
|
|
|
if (c.value<0) {
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
DivInstrumentFM::Operator op=ins->fm.op[i];
|
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[i];
|
|
|
|
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
|
|
|
unsigned short baseAddr=chanOffs[c.chan]|opOffs[orderedOps[c.value]];
|
|
|
|
rWrite(baseAddr+0x50,(c.value2&31)|(op.rs<<6));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2021-05-28 05:36:25 +00:00
|
|
|
case DIV_ALWAYS_SET_VOLUME:
|
|
|
|
return 0;
|
|
|
|
break;
|
2021-05-17 20:06:11 +00:00
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 127;
|
|
|
|
break;
|
2021-05-18 07:53:59 +00:00
|
|
|
case DIV_CMD_PRE_PORTA:
|
|
|
|
break;
|
2021-12-06 07:59:12 +00:00
|
|
|
case DIV_CMD_PRE_NOTE:
|
|
|
|
break;
|
2021-05-12 22:19:18 +00:00
|
|
|
default:
|
2021-12-06 08:26:33 +00:00
|
|
|
//printf("WARNING: unimplemented command %d\n",c.cmd);
|
2021-05-12 22:19:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-12-21 06:29:07 +00:00
|
|
|
void DivPlatformGenesis::forceIns() {
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
}
|
|
|
|
if (dacMode) {
|
|
|
|
rWrite(0x2b,0x80);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 18:14:38 +00:00
|
|
|
void DivPlatformGenesis::reset() {
|
|
|
|
while (!writes.empty()) writes.pop();
|
2021-05-12 22:19:18 +00:00
|
|
|
OPN2_Reset(&fm);
|
2021-05-13 07:39:26 +00:00
|
|
|
for (int i=0; i<10; i++) {
|
2021-12-11 18:14:38 +00:00
|
|
|
chan[i]=DivPlatformGenesis::Channel();
|
2021-05-13 07:39:26 +00:00
|
|
|
chan[i].vol=0x7f;
|
|
|
|
}
|
|
|
|
|
2021-05-13 08:09:56 +00:00
|
|
|
for (int i=0; i<512; i++) {
|
2021-05-16 08:03:23 +00:00
|
|
|
oldWrites[i]=-1;
|
2021-05-13 08:09:56 +00:00
|
|
|
pendingWrites[i]=-1;
|
|
|
|
}
|
|
|
|
|
2021-05-13 07:39:26 +00:00
|
|
|
lastBusy=60;
|
|
|
|
dacMode=0;
|
|
|
|
dacPeriod=0;
|
|
|
|
dacPos=0;
|
|
|
|
dacRate=0;
|
|
|
|
dacSample=-1;
|
2021-12-09 08:13:37 +00:00
|
|
|
sampleBank=0;
|
2021-05-13 07:39:26 +00:00
|
|
|
|
2021-05-17 01:49:54 +00:00
|
|
|
extMode=false;
|
|
|
|
|
2021-05-13 07:39:26 +00:00
|
|
|
// LFO
|
2021-12-21 06:29:07 +00:00
|
|
|
immWrite(0x22,0x08);
|
2021-05-12 22:19:18 +00:00
|
|
|
|
2021-05-13 07:39:26 +00:00
|
|
|
delay=0;
|
2021-05-15 21:59:57 +00:00
|
|
|
|
|
|
|
// PSG
|
2021-12-11 18:14:38 +00:00
|
|
|
psg.reset();
|
2021-05-15 21:59:57 +00:00
|
|
|
psgClocks=0;
|
|
|
|
psgOut=0;
|
2021-12-11 18:14:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DivPlatformGenesis::isStereo() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DivPlatformGenesis::keyOffAffectsArp(int ch) {
|
|
|
|
return (ch>5);
|
|
|
|
}
|
|
|
|
|
2021-12-29 07:08:50 +00:00
|
|
|
bool DivPlatformGenesis::keyOffAffectsPorta(int ch) {
|
|
|
|
return (ch>5);
|
|
|
|
}
|
|
|
|
|
2022-01-18 04:59:52 +00:00
|
|
|
void DivPlatformGenesis::notifyInsChange(int ins) {
|
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
if (i>5) {
|
|
|
|
psg.notifyInsChange(ins);
|
|
|
|
} else if (chan[i].ins==ins) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:36:02 +00:00
|
|
|
void DivPlatformGenesis::notifyInsDeletion(void* ins) {
|
|
|
|
psg.notifyInsDeletion(ins);
|
|
|
|
}
|
|
|
|
|
2021-12-15 22:32:08 +00:00
|
|
|
void DivPlatformGenesis::setPAL(bool pal) {
|
2021-12-11 18:14:38 +00:00
|
|
|
if (pal) {
|
|
|
|
rate=211125;
|
|
|
|
} else {
|
|
|
|
rate=213068;
|
|
|
|
}
|
2021-12-15 22:32:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformGenesis::init(DivEngine* p, int channels, int sugRate, bool pal) {
|
|
|
|
parent=p;
|
2022-01-17 04:21:27 +00:00
|
|
|
dumpWrites=false;
|
2021-12-21 21:02:31 +00:00
|
|
|
skipRegisterWrites=false;
|
2021-12-18 08:25:42 +00:00
|
|
|
for (int i=0; i<10; i++) {
|
|
|
|
isMuted[i]=false;
|
|
|
|
}
|
2021-12-15 22:32:08 +00:00
|
|
|
setPAL(pal);
|
2021-12-11 18:14:38 +00:00
|
|
|
// PSG
|
|
|
|
psg.init(p,4,sugRate,pal);
|
|
|
|
|
|
|
|
reset();
|
2021-05-12 22:19:18 +00:00
|
|
|
return 10;
|
|
|
|
}
|
2021-12-15 05:37:27 +00:00
|
|
|
|
|
|
|
void DivPlatformGenesis::quit() {
|
|
|
|
psg.quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformGenesis::~DivPlatformGenesis() {
|
|
|
|
}
|