Merge branch 'master' into es5506_alt
This commit is contained in:
commit
a793bed56d
65 changed files with 4981 additions and 395 deletions
|
|
@ -353,9 +353,9 @@ void DivPlatformArcade::tick(bool sysTick) {
|
|||
chan[i].freq=chan[i].baseFreq+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
if (!parent->song.oldArpStrategy) {
|
||||
if (chan[i].fixedArp) {
|
||||
chan[i].freq=(chan[i].baseNoteOverride<<7)+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
chan[i].freq=(chan[i].baseNoteOverride<<6)+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
} else {
|
||||
chan[i].freq+=chan[i].arpOff<<7;
|
||||
chan[i].freq+=chan[i].arpOff<<6;
|
||||
}
|
||||
}
|
||||
if (chan[i].freq<0) chan[i].freq=0;
|
||||
|
|
|
|||
|
|
@ -830,6 +830,9 @@ void DivPlatformAY8910::setFlags(const DivConfig& flags) {
|
|||
case 14:
|
||||
chipClock=1536000;
|
||||
break;
|
||||
case 15:
|
||||
chipClock=38400*13*4; // 31948800/16
|
||||
break;
|
||||
default:
|
||||
chipClock=COLOR_NTSC/2.0;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@
|
|||
return 2; \
|
||||
}
|
||||
|
||||
#define IS_EXTCH_MUTED (isOpMuted[0] && isOpMuted[1] && isOpMuted[2] && isOpMuted[3])
|
||||
|
||||
class DivPlatformOPN: public DivPlatformFMBase {
|
||||
protected:
|
||||
const unsigned short ADDR_MULT_DT=0x30;
|
||||
|
|
@ -147,17 +149,21 @@ class DivPlatformOPN: public DivPlatformFMBase {
|
|||
double fmFreqBase;
|
||||
unsigned int fmDivBase;
|
||||
unsigned int ayDiv;
|
||||
unsigned char csmChan;
|
||||
unsigned char lfoValue;
|
||||
bool extSys;
|
||||
|
||||
DivConfig ayFlags;
|
||||
|
||||
friend void putDispatchChip(void*,int);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
DivPlatformOPN(double f=9440540.0, unsigned int d=72, unsigned int a=32, bool isExtSys=false):
|
||||
DivPlatformOPN(double f=9440540.0, unsigned int d=72, unsigned int a=32, bool isExtSys=false, unsigned char cc=255):
|
||||
DivPlatformFMBase(),
|
||||
fmFreqBase(f),
|
||||
fmDivBase(d),
|
||||
ayDiv(a),
|
||||
csmChan(cc),
|
||||
lfoValue(0),
|
||||
extSys(isExtSys) {}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -479,7 +479,7 @@ void DivPlatformGenesis::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<7; i++) {
|
||||
for (int i=0; i<csmChan; i++) {
|
||||
if (i==2 && extMode) continue;
|
||||
if (chan[i].freqChanged) {
|
||||
if (parent->song.linearPitch==2) {
|
||||
|
|
@ -554,7 +554,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_FM);
|
||||
if (c.chan==7 && extMode && softPCM) { // CSM
|
||||
if (c.chan==csmChan && extMode) { // CSM
|
||||
chan[c.chan].macroInit(ins);
|
||||
chan[c.chan].insChanged=false;
|
||||
|
||||
|
|
@ -691,7 +691,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_NOTE_OFF:
|
||||
if (c.chan>=5 && c.chan<7) {
|
||||
if (c.chan>=5 && c.chan<csmChan) {
|
||||
chan[c.chan].dacSample=-1;
|
||||
if (dumpWrites) addWrite(0xffff0002,0);
|
||||
if (parent->song.brokenDACMode) {
|
||||
|
|
@ -786,7 +786,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (c.chan==7) {
|
||||
if (c.chan==csmChan) {
|
||||
int destFreq=NOTE_PERIODIC(c.value2);
|
||||
bool return2=false;
|
||||
if (destFreq>chan[c.chan].baseFreq) {
|
||||
|
|
@ -855,7 +855,7 @@ int DivPlatformGenesis::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_LEGATO: {
|
||||
if (c.chan==7) {
|
||||
if (c.chan==csmChan) {
|
||||
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
||||
} else if (c.chan>=5 && chan[c.chan].furnaceDac && chan[c.chan].dacMode) {
|
||||
chan[c.chan].baseFreq=parent->calcBaseFreq(1,1,c.value,false);
|
||||
|
|
@ -1222,7 +1222,7 @@ void DivPlatformGenesis::poke(std::vector<DivRegWrite>& wlist) {
|
|||
}
|
||||
|
||||
int DivPlatformGenesis::getPortaFloor(int ch) {
|
||||
return (ch>5)?12:0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DivPlatformGenesis::setYMFM(bool use) {
|
||||
|
|
|
|||
|
|
@ -86,8 +86,6 @@ class DivPlatformGenesis: public DivPlatformOPN {
|
|||
ymfm::ym2612* fm_ymfm;
|
||||
ymfm::ym2612::output_data out_ymfm;
|
||||
DivYM2612Interface iface;
|
||||
|
||||
unsigned char lfoValue;
|
||||
|
||||
int softPCMTimer;
|
||||
|
||||
|
|
@ -133,7 +131,7 @@ class DivPlatformGenesis: public DivPlatformOPN {
|
|||
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
|
||||
void quit();
|
||||
DivPlatformGenesis():
|
||||
DivPlatformOPN(9440540.0, 72, 32) {}
|
||||
DivPlatformOPN(9440540.0, 72, 32, false, 7) {}
|
||||
~DivPlatformGenesis();
|
||||
};
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#define CHIP_DIVIDER fmDivBase
|
||||
|
||||
#define IS_REALLY_MUTED(x) (isMuted[x] && (x<5 || !softPCM || (isMuted[5] && isMuted[6])))
|
||||
#define IS_EXTCH_MUTED (isOpMuted[0] && isOpMuted[1] && isOpMuted[2] && isOpMuted[3])
|
||||
|
||||
int DivPlatformGenesisExt::dispatch(DivCommand c) {
|
||||
if (c.chan<2) {
|
||||
|
|
@ -220,14 +219,14 @@ int DivPlatformGenesisExt::dispatch(DivCommand c) {
|
|||
rWrite(chanOffs[2]+ADDR_FB_ALG,(chan[2].state.alg&7)|(chan[2].state.fb<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
case DIV_CMD_FM_MULT: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.mult=c.value2&15;
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
case DIV_CMD_FM_TL: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.tl=c.value2;
|
||||
|
|
@ -454,7 +453,7 @@ void DivPlatformGenesisExt::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
if (writeSomething) {
|
||||
if (chan[7].active) { // CSM
|
||||
if (chan[csmChan].active) { // CSM
|
||||
writeMask^=0xf0;
|
||||
}
|
||||
/*printf(
|
||||
|
|
@ -588,18 +587,18 @@ void DivPlatformGenesisExt::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
if (extMode && softPCM) {
|
||||
if (chan[7].freqChanged) {
|
||||
chan[7].freq=parent->calcFreq(chan[7].baseFreq,chan[7].pitch,chan[7].fixedArp?chan[7].baseNoteOverride:chan[7].arpOff,chan[7].fixedArp,true,0,chan[7].pitch2,chipClock,CHIP_DIVIDER);
|
||||
if (chan[7].freq<1) chan[7].freq=1;
|
||||
if (chan[7].freq>1024) chan[7].freq=1024;
|
||||
int wf=0x400-chan[7].freq;
|
||||
if (extMode) {
|
||||
if (chan[csmChan].freqChanged) {
|
||||
chan[csmChan].freq=parent->calcFreq(chan[csmChan].baseFreq,chan[csmChan].pitch,chan[csmChan].fixedArp?chan[csmChan].baseNoteOverride:chan[csmChan].arpOff,chan[csmChan].fixedArp,true,0,chan[csmChan].pitch2,chipClock,CHIP_DIVIDER);
|
||||
if (chan[csmChan].freq<1) chan[csmChan].freq=1;
|
||||
if (chan[csmChan].freq>1024) chan[csmChan].freq=1024;
|
||||
int wf=0x400-chan[csmChan].freq;
|
||||
immWrite(0x24,wf>>2);
|
||||
immWrite(0x25,wf&3);
|
||||
chan[7].freqChanged=false;
|
||||
chan[csmChan].freqChanged=false;
|
||||
}
|
||||
|
||||
if (chan[7].keyOff || chan[7].keyOn) {
|
||||
if (chan[csmChan].keyOff || chan[csmChan].keyOn) {
|
||||
writeNoteOn=true;
|
||||
for (int i=0; i<4; i++) {
|
||||
writeMask|=opChan[i].active<<(4+i);
|
||||
|
|
@ -608,7 +607,7 @@ void DivPlatformGenesisExt::tick(bool sysTick) {
|
|||
}
|
||||
|
||||
if (writeNoteOn) {
|
||||
if (chan[7].active) { // CSM
|
||||
if (chan[csmChan].active) { // CSM
|
||||
writeMask^=0xf0;
|
||||
}
|
||||
/*printf(
|
||||
|
|
@ -621,14 +620,14 @@ void DivPlatformGenesisExt::tick(bool sysTick) {
|
|||
immWrite(0x28,writeMask);
|
||||
}
|
||||
|
||||
if (extMode && softPCM) {
|
||||
if (chan[7].keyOn) {
|
||||
if (extMode) {
|
||||
if (chan[csmChan].keyOn) {
|
||||
immWrite(0x27,0x81);
|
||||
chan[7].keyOn=false;
|
||||
chan[csmChan].keyOn=false;
|
||||
}
|
||||
if (chan[7].keyOff) {
|
||||
if (chan[csmChan].keyOff) {
|
||||
immWrite(0x27,0x40);
|
||||
chan[7].keyOff=false;
|
||||
chan[csmChan].keyOff=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -686,10 +685,10 @@ void DivPlatformGenesisExt::forceIns() {
|
|||
opChan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
if (extMode && softPCM && chan[7].active) { // CSM
|
||||
chan[7].insChanged=true;
|
||||
chan[7].freqChanged=true;
|
||||
chan[7].keyOn=true;
|
||||
if (extMode && chan[csmChan].active) { // CSM
|
||||
chan[csmChan].insChanged=true;
|
||||
chan[csmChan].freqChanged=true;
|
||||
chan[csmChan].keyOn=true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -701,7 +700,7 @@ void* DivPlatformGenesisExt::getChanState(int ch) {
|
|||
|
||||
DivMacroInt* DivPlatformGenesisExt::getChanMacroInt(int ch) {
|
||||
if (ch>=6) return &chan[ch-3].std;
|
||||
if (ch>=2) return NULL; // currently not implemented
|
||||
if (ch>=2) return &opChan[ch-2].std;
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
|
|
@ -747,6 +746,10 @@ int DivPlatformGenesisExt::getPortaFloor(int ch) {
|
|||
return (ch>8)?12:0;
|
||||
}
|
||||
|
||||
void DivPlatformGenesisExt::setCSMChannel(unsigned char ch) {
|
||||
csmChan=ch;
|
||||
}
|
||||
|
||||
int DivPlatformGenesisExt::init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags) {
|
||||
DivPlatformGenesis::init(parent,channels,sugRate,flags);
|
||||
for (int i=0; i<4; i++) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ class DivPlatformGenesisExt: public DivPlatformGenesis {
|
|||
bool keyOffAffectsPorta(int ch);
|
||||
void notifyInsChange(int ins);
|
||||
int getPortaFloor(int ch);
|
||||
void setCSMChannel(unsigned char ch);
|
||||
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
|
||||
void quit();
|
||||
~DivPlatformGenesisExt();
|
||||
|
|
|
|||
|
|
@ -529,10 +529,10 @@ void DivPlatformK007232::renderSamples(int sysID) {
|
|||
}
|
||||
|
||||
const int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT);
|
||||
int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-1,length);
|
||||
int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-2,length);
|
||||
if (actualLength>0) {
|
||||
if (actualLength>131072-1) {
|
||||
actualLength=131072-1;
|
||||
if (actualLength>131072-2) {
|
||||
actualLength=131072-2;
|
||||
}
|
||||
if ((memPos&0xfe0000)!=((memPos+actualLength+1)&0xfe0000)) {
|
||||
memPos=(memPos+0x1ffff)&0xfe0000;
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ void DivPlatformMSM6295::renderSamples(int sysID) {
|
|||
// sample data
|
||||
size_t memPos=128*8;
|
||||
int sampleCount=parent->song.sampleLen;
|
||||
if (sampleCount>128) sampleCount=128;
|
||||
if (sampleCount>127) sampleCount=127;
|
||||
for (int i=0; i<sampleCount; i++) {
|
||||
DivSample* s=parent->song.sample[i];
|
||||
if (!s->renderOn[0][sysID]) {
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#define _USE_MATH_DEFINES
|
||||
#include "pcmdac.h"
|
||||
#include "../engine.h"
|
||||
#include "../filter.h"
|
||||
#include <math.h>
|
||||
|
||||
// to ease the driver, freqency register is a 8.16 counter relative to output sample rate
|
||||
|
|
@ -103,7 +104,50 @@ void DivPlatformPCMDAC::acquire(short* bufL, short* bufR, size_t start, size_t l
|
|||
}
|
||||
}
|
||||
if (chan[0].audPos>=0 && chan[0].audPos<(int)s->samples) {
|
||||
output=s->data16[chan[0].audPos];
|
||||
int s_4=((chan[0].audPos-4)>=0)?s->data16[chan[0].audPos-4]:0;
|
||||
int s_3=((chan[0].audPos-3)>=0)?s->data16[chan[0].audPos-3]:0;
|
||||
int s_2=((chan[0].audPos-2)>=0)?s->data16[chan[0].audPos-2]:0;
|
||||
int s_1=((chan[0].audPos-1)>=0)?s->data16[chan[0].audPos-1]:0;
|
||||
int s0=s->data16[chan[0].audPos];
|
||||
int s1=((chan[0].audPos+1)<(int)s->samples)?s->data16[chan[0].audPos+1]:0;
|
||||
int s2=((chan[0].audPos+2)<(int)s->samples)?s->data16[chan[0].audPos+2]:0;
|
||||
int s3=((chan[0].audPos+3)<(int)s->samples)?s->data16[chan[0].audPos+3]:0;
|
||||
switch (interp) {
|
||||
case 1: // linear
|
||||
output=s0+((s1-s0)*(chan[0].audSub&0xffff)>>16);
|
||||
break;
|
||||
case 2: { // cubic
|
||||
float* cubicTable=DivFilterTables::getCubicTable();
|
||||
float* t=&cubicTable[((chan[0].audSub&0xffff)>>6)<<2];
|
||||
float result=(float)s_1*t[0]+(float)s0*t[1]+(float)s1*t[2]+(float)s2*t[3];
|
||||
if (result<-32768) result=-32768;
|
||||
if (result>32767) result=32767;
|
||||
output=result;
|
||||
break;
|
||||
}
|
||||
case 3: { // sinc
|
||||
float* sincTable=DivFilterTables::getSincTable8();
|
||||
float* t1=&sincTable[(8191-((chan[0].audSub&0xffff)>>3))<<2];
|
||||
float* t2=&sincTable[((chan[0].audSub&0xffff)>>3)<<2];
|
||||
float result=(
|
||||
s_4*t2[3]+
|
||||
s_3*t2[2]+
|
||||
s_2*t2[1]+
|
||||
s_1*t2[0]+
|
||||
s0*t1[0]+
|
||||
s1*t1[1]+
|
||||
s2*t1[2]+
|
||||
s3*t1[3]
|
||||
);
|
||||
if (result<-32768) result=-32768;
|
||||
if (result>32767) result=32767;
|
||||
output=result;
|
||||
break;
|
||||
}
|
||||
default: // none
|
||||
output=s0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
chan[0].sample=-1;
|
||||
|
|
@ -398,6 +442,8 @@ void DivPlatformPCMDAC::setFlags(const DivConfig& flags) {
|
|||
chipClock=rate;
|
||||
outDepth=(flags.getInt("outDepth",15))&15;
|
||||
outStereo=flags.getBool("stereo",true);
|
||||
interp=flags.getInt("interpolation",0);
|
||||
oscBuf->rate=rate;
|
||||
}
|
||||
|
||||
int DivPlatformPCMDAC::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
||||
|
|
|
|||
|
|
@ -55,6 +55,12 @@ class DivPlatformPCMDAC: public DivDispatch {
|
|||
DivDispatchOscBuffer* oscBuf;
|
||||
bool isMuted;
|
||||
int outDepth;
|
||||
// valid values:
|
||||
// - 0: none
|
||||
// - 1: linear
|
||||
// - 2: cubic spline
|
||||
// - 3: sinc
|
||||
int interp;
|
||||
bool outStereo;
|
||||
|
||||
friend void putDispatchChip(void*,int);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,20 @@
|
|||
#define CHIP_DIVIDER 1
|
||||
|
||||
const char* regCheatSheetPokeMini[]={
|
||||
"Period", "0",
|
||||
"TMR3_SCALE", "1C",
|
||||
"TMR3_OSC", "1D",
|
||||
"TMR3_CTRL_L", "48",
|
||||
"TMR3_CTRL_H", "49",
|
||||
"TMR3_PRE_L", "4A",
|
||||
"TMR3_PRE_H", "4B",
|
||||
"TMR3_PVT_L", "4C",
|
||||
"TMR3_PVT_H", "4D",
|
||||
"TMR3_CNT_L", "4E",
|
||||
"TMR3_CNT_H", "4F",
|
||||
"IO_DIR", "60",
|
||||
"IO_DATA", "61",
|
||||
"AUD_CTRL", "70",
|
||||
"AUD_VOL", "71",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
@ -42,6 +55,37 @@ const char** DivPlatformPokeMini::getRegisterSheet() {
|
|||
return regCheatSheetPokeMini;
|
||||
}
|
||||
|
||||
void DivPlatformPokeMini::rWrite(unsigned char addr, unsigned char val) {
|
||||
if (addr<128) regPool[addr]=val;
|
||||
switch (addr) {
|
||||
case 0x1c:
|
||||
// ignore
|
||||
break;
|
||||
case 0x1d:
|
||||
// ignore
|
||||
break;
|
||||
case 0x48: case 0x49:
|
||||
on=val&4;
|
||||
if (val&2) pos=0;
|
||||
break;
|
||||
case 0x4a:
|
||||
preset=(preset&0xff00)|val;
|
||||
break;
|
||||
case 0x4b:
|
||||
preset=(preset&0xff)|(val<<8);
|
||||
break;
|
||||
case 0x4c:
|
||||
pivot=(pivot&0xff00)|val;
|
||||
break;
|
||||
case 0x4d:
|
||||
pivot=(pivot&0xff)|(val<<8);
|
||||
break;
|
||||
case 0x71:
|
||||
vol=val&3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPokeMini::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||
int out=0;
|
||||
for (size_t i=start; i<start+len; i++) {
|
||||
|
|
@ -72,7 +116,7 @@ void DivPlatformPokeMini::tick(bool sysTick) {
|
|||
chan[i].std.next();
|
||||
if (chan[i].std.vol.had) {
|
||||
chan[i].outVol=VOL_SCALE_LINEAR(chan[i].vol,chan[i].std.vol.val,2);
|
||||
vol=(chan[i].outVol==2)?3:chan[i].outVol;
|
||||
rWrite(0x71,(chan[i].outVol==2)?3:chan[i].outVol);
|
||||
}
|
||||
if (NEW_ARP_STRAT) {
|
||||
chan[i].handleArp();
|
||||
|
|
@ -100,13 +144,16 @@ void DivPlatformPokeMini::tick(bool sysTick) {
|
|||
if (chan[i].freq<0) chan[i].freq=0;
|
||||
if (chan[i].freq>65535) chan[i].freq=65535;
|
||||
if (chan[i].keyOn) {
|
||||
on=true;
|
||||
rWrite(0x48,4);
|
||||
}
|
||||
if (chan[i].keyOff) {
|
||||
on=false;
|
||||
rWrite(0x48,0);
|
||||
}
|
||||
preset=chan[i].freq;
|
||||
pivot=(chan[i].duty*preset)>>8;
|
||||
rWrite(0x4a,chan[i].freq&0xff);
|
||||
rWrite(0x4b,chan[i].freq>>8);
|
||||
int pvt=(chan[i].duty*chan[i].freq)>>8;
|
||||
rWrite(0x4c,pvt&0xff);
|
||||
rWrite(0x4d,pvt>>8);
|
||||
if (chan[i].keyOn) chan[i].keyOn=false;
|
||||
if (chan[i].keyOff) chan[i].keyOff=false;
|
||||
chan[i].freqChanged=false;
|
||||
|
|
@ -122,7 +169,7 @@ int DivPlatformPokeMini::dispatch(DivCommand c) {
|
|||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
}
|
||||
vol=(chan[c.chan].outVol==2)?3:chan[c.chan].outVol;
|
||||
rWrite(0x71,(chan[c.chan].outVol==2)?3:chan[c.chan].outVol);
|
||||
chan[c.chan].active=true;
|
||||
chan[c.chan].keyOn=true;
|
||||
chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_POKEMINI));
|
||||
|
|
@ -151,7 +198,7 @@ int DivPlatformPokeMini::dispatch(DivCommand c) {
|
|||
chan[c.chan].outVol=c.value;
|
||||
}
|
||||
if (chan[c.chan].active) {
|
||||
on=chan[c.chan].vol;
|
||||
rWrite(0x71,(chan[c.chan].outVol==2)?3:chan[c.chan].outVol);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -186,14 +233,13 @@ int DivPlatformPokeMini::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_LEGATO:
|
||||
if (c.chan==3) break;
|
||||
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0)));
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
break;
|
||||
case DIV_CMD_PRE_PORTA:
|
||||
if (chan[c.chan].active && c.value2) {
|
||||
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_BEEPER));
|
||||
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_POKEMINI));
|
||||
}
|
||||
if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note);
|
||||
chan[c.chan].inPorta=c.value;
|
||||
|
|
@ -239,18 +285,11 @@ DivDispatchOscBuffer* DivPlatformPokeMini::getOscBuffer(int ch) {
|
|||
}
|
||||
|
||||
unsigned char* DivPlatformPokeMini::getRegisterPool() {
|
||||
if (on) {
|
||||
regPool[0]=preset;
|
||||
regPool[1]=preset>>8;
|
||||
} else {
|
||||
regPool[0]=0;
|
||||
regPool[1]=0;
|
||||
}
|
||||
return regPool;
|
||||
}
|
||||
|
||||
int DivPlatformPokeMini::getRegisterPoolSize() {
|
||||
return 2;
|
||||
return 128;
|
||||
}
|
||||
|
||||
void DivPlatformPokeMini::reset() {
|
||||
|
|
@ -272,7 +311,7 @@ void DivPlatformPokeMini::reset() {
|
|||
pivot=0;
|
||||
elapsedMain=0;
|
||||
|
||||
memset(regPool,0,2);
|
||||
memset(regPool,0,128);
|
||||
}
|
||||
|
||||
bool DivPlatformPokeMini::keyOffAffectsArp(int ch) {
|
||||
|
|
@ -294,11 +333,11 @@ void DivPlatformPokeMini::notifyInsDeletion(void* ins) {
|
|||
}
|
||||
|
||||
void DivPlatformPokeMini::poke(unsigned int addr, unsigned short val) {
|
||||
// ???
|
||||
rWrite(addr,val);
|
||||
}
|
||||
|
||||
void DivPlatformPokeMini::poke(std::vector<DivRegWrite>& wlist) {
|
||||
// ???
|
||||
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
||||
}
|
||||
|
||||
int DivPlatformPokeMini::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
||||
|
|
|
|||
|
|
@ -37,9 +37,11 @@ class DivPlatformPokeMini: public DivDispatch {
|
|||
int pos;
|
||||
unsigned char timerScale, vol;
|
||||
unsigned short preset, pivot;
|
||||
unsigned char regPool[2];
|
||||
unsigned char regPool[128];
|
||||
unsigned short elapsedMain;
|
||||
|
||||
void rWrite(unsigned char addr, unsigned char val);
|
||||
|
||||
friend void putDispatchChip(void*,int);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
|
||||
|
|
|
|||
504
src/engine/platform/pokey.cpp
Normal file
504
src/engine/platform/pokey.cpp
Normal file
|
|
@ -0,0 +1,504 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "pokey.h"
|
||||
#include "../engine.h"
|
||||
#include "../../ta-log.h"
|
||||
|
||||
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} }
|
||||
|
||||
#define CHIP_DIVIDER 1
|
||||
|
||||
const char* regCheatSheetPOKEY[]={
|
||||
"AUDF1", "0",
|
||||
"AUDC1", "1",
|
||||
"AUDF2", "2",
|
||||
"AUDC2", "3",
|
||||
"AUDF3", "4",
|
||||
"AUDC3", "5",
|
||||
"AUDF4", "6",
|
||||
"AUDC4", "7",
|
||||
"AUDCTL", "8",
|
||||
NULL
|
||||
};
|
||||
|
||||
// LLsLSsLLsSLsLLn
|
||||
const unsigned char snapPeriodLong[15]={
|
||||
0, 1, 1, 3, 3, 6, 6, 7, 7, 10, 10, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
const unsigned char snapPeriodShort[15]={
|
||||
2, 2, 2, 2, 5, 5, 5, 8, 8, 11, 11, 11, 11, 17, 17
|
||||
};
|
||||
|
||||
// LsSLsLLnLLsLSsL
|
||||
const unsigned char snapPeriodLong16[15]={
|
||||
0, 0, 3, 3, 3, 5, 6, 6, 8, 9, 9, 11, 11, 14, 14
|
||||
};
|
||||
|
||||
const unsigned char snapPeriodShort16[15]={
|
||||
1, 1, 1, 4, 4, 4, 4, 4, 10, 10, 10, 10, 13, 13, 13
|
||||
};
|
||||
|
||||
const unsigned char waveMap[8]={
|
||||
0, 1, 2, 3, 4, 5, 6, 6
|
||||
};
|
||||
|
||||
const char** DivPlatformPOKEY::getRegisterSheet() {
|
||||
return regCheatSheetPOKEY;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::acquire(short* bufL, short* bufR, size_t start, size_t len) {
|
||||
if (useAltASAP) {
|
||||
acquireASAP(bufL, start, len);
|
||||
} else {
|
||||
acquireMZ(bufL, start, len);
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::acquireMZ(short* buf, size_t start, size_t len) {
|
||||
for (size_t h=start; h<start+len; h++) {
|
||||
while (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
Update_pokey_sound_mz(&pokey,w.addr,w.val,0);
|
||||
regPool[w.addr&0x0f]=w.val;
|
||||
writes.pop();
|
||||
}
|
||||
|
||||
mzpokeysnd_process_16(&pokey,&buf[h],1);
|
||||
|
||||
if (++oscBufDelay>=14) {
|
||||
oscBufDelay=0;
|
||||
oscBuf[0]->data[oscBuf[0]->needle++]=pokey.outvol_0<<11;
|
||||
oscBuf[1]->data[oscBuf[1]->needle++]=pokey.outvol_1<<11;
|
||||
oscBuf[2]->data[oscBuf[2]->needle++]=pokey.outvol_2<<11;
|
||||
oscBuf[3]->data[oscBuf[3]->needle++]=pokey.outvol_3<<11;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::acquireASAP(short* buf, size_t start, size_t len) {
|
||||
while (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
altASAP.write(w.addr, w.val);
|
||||
writes.pop();
|
||||
}
|
||||
|
||||
for (size_t h=start; h<start+len; h++) {
|
||||
if (++oscBufDelay>=2) {
|
||||
oscBufDelay=0;
|
||||
buf[h]=altASAP.sampleAudio(oscBuf);
|
||||
} else {
|
||||
buf[h]=altASAP.sampleAudio();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::tick(bool sysTick) {
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].std.next();
|
||||
if (chan[i].std.vol.had) {
|
||||
chan[i].outVol=VOL_SCALE_LINEAR(chan[i].vol&15,MIN(15,chan[i].std.vol.val),15);
|
||||
chan[i].ctlChanged=true;
|
||||
}
|
||||
if (NEW_ARP_STRAT) {
|
||||
chan[i].handleArp();
|
||||
} else if (chan[i].std.arp.had) {
|
||||
if (!chan[i].inPorta) {
|
||||
chan[i].baseFreq=NOTE_PERIODIC(parent->calcArp(chan[i].note,chan[i].std.arp.val));
|
||||
}
|
||||
chan[i].freqChanged=true;
|
||||
}
|
||||
if (chan[i].std.duty.had) {
|
||||
audctl=chan[i].std.duty.val;
|
||||
audctlChanged=true;
|
||||
}
|
||||
if (chan[i].std.wave.had) {
|
||||
chan[i].wave=chan[i].std.wave.val;
|
||||
chan[i].ctlChanged=true;
|
||||
chan[i].freqChanged=true;
|
||||
}
|
||||
if (chan[i].std.pitch.had) {
|
||||
if (chan[i].std.pitch.mode) {
|
||||
chan[i].pitch2+=chan[i].std.pitch.val;
|
||||
CLAMP_VAR(chan[i].pitch2,-32768,32767);
|
||||
} else {
|
||||
chan[i].pitch2=chan[i].std.pitch.val;
|
||||
}
|
||||
chan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
|
||||
if (audctlChanged) {
|
||||
audctlChanged=false;
|
||||
rWrite(8,audctl);
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].freqChanged=true;
|
||||
chan[i].ctlChanged=true;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i=0; i<4; i++) {
|
||||
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
||||
chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride:chan[i].arpOff,chan[i].fixedArp,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER);
|
||||
|
||||
if ((i==0 && !(audctl&64)) || (i==2 && !(audctl&32)) || i==1 || i==3) {
|
||||
chan[i].freq/=7;
|
||||
switch (chan[i].wave) {
|
||||
case 6:
|
||||
chan[i].freq/=5;
|
||||
chan[i].freq>>=1;
|
||||
break;
|
||||
case 7:
|
||||
if (audctl&1) {
|
||||
chan[i].freq/=5;
|
||||
} else {
|
||||
chan[i].freq/=15;
|
||||
}
|
||||
chan[i].freq>>=1;
|
||||
break;
|
||||
default:
|
||||
chan[i].freq>>=2;
|
||||
break;
|
||||
}
|
||||
} else if ((i==0 && audctl&64) || (i==2 && audctl&32)) {
|
||||
switch (chan[i].wave) {
|
||||
case 6:
|
||||
chan[i].freq<<=1;
|
||||
chan[i].freq/=5;
|
||||
break;
|
||||
case 7:
|
||||
chan[i].freq<<=1;
|
||||
chan[i].freq/=15;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (audctl&1 && !((i==0 && audctl&64) || (i==2 && audctl&32))) {
|
||||
chan[i].freq>>=2;
|
||||
}
|
||||
|
||||
if (--chan[i].freq<0) chan[i].freq=0;
|
||||
|
||||
// snap buzz periods
|
||||
int minFreq8=255;
|
||||
if (chan[i].wave==7) {
|
||||
if ((i==0 && audctl&64) || (i==2 && audctl&32)) {
|
||||
chan[i].freq=15*(chan[i].freq/15)+snapPeriodLong16[(chan[i].freq%15)]+1;
|
||||
} else {
|
||||
if (!(audctl&1)) chan[i].freq=15*(chan[i].freq/15)+snapPeriodLong[(chan[i].freq%15)];
|
||||
}
|
||||
} else if (chan[i].wave==6) {
|
||||
if ((i==0 && audctl&64) || (i==2 && audctl&32)) {
|
||||
chan[i].freq=15*(chan[i].freq/15)+snapPeriodShort16[(chan[i].freq%15)]+1;
|
||||
} else {
|
||||
if (!(audctl&1)) chan[i].freq=15*(chan[i].freq/15)+snapPeriodShort[(chan[i].freq%15)];
|
||||
}
|
||||
minFreq8=251;
|
||||
}
|
||||
|
||||
if ((i==0 && audctl&16) || (i==2 && audctl&8)) {
|
||||
if (chan[i].freq>65535) chan[i].freq=65535;
|
||||
} else {
|
||||
if (chan[i].freq>minFreq8) chan[i].freq=minFreq8;
|
||||
}
|
||||
|
||||
// write frequency
|
||||
if ((i==1 && audctl&16) || (i==3 && audctl&8)) {
|
||||
// ignore - channel is paired
|
||||
} else {
|
||||
rWrite(i<<1,chan[i].freq&0xff);
|
||||
if ((i==0 && audctl&16) || (i==2 && audctl&8)) {
|
||||
rWrite((1+i)<<1,chan[i].freq>>8);
|
||||
}
|
||||
}
|
||||
|
||||
if (chan[i].keyOff) {
|
||||
chan[i].ctlChanged=true;
|
||||
}
|
||||
if (chan[i].keyOn) chan[i].keyOn=false;
|
||||
if (chan[i].keyOff) chan[i].keyOff=false;
|
||||
chan[i].freqChanged=false;
|
||||
}
|
||||
if (chan[i].ctlChanged) {
|
||||
unsigned char val=((chan[i].active && !isMuted[i])?(chan[i].outVol&15):0)|(waveMap[chan[i].wave&7]<<5);
|
||||
chan[i].ctlChanged=false;
|
||||
if ((i==1 && audctl&16) || (i==3 && audctl&8)) {
|
||||
// ignore - channel is paired
|
||||
} else if ((i==0 && audctl&16) || (i==0 && audctl&8)) {
|
||||
rWrite(1+(i<<1),0);
|
||||
rWrite(3+(i<<1),val);
|
||||
} else {
|
||||
|
||||
rWrite(1+(i<<1),val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int DivPlatformPOKEY::dispatch(DivCommand c) {
|
||||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_POKEY);
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
}
|
||||
chan[c.chan].active=true;
|
||||
chan[c.chan].keyOn=true;
|
||||
chan[c.chan].macroInit(ins);
|
||||
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) {
|
||||
chan[c.chan].outVol=chan[c.chan].vol;
|
||||
chan[c.chan].ctlChanged=true;
|
||||
}
|
||||
chan[c.chan].insChanged=false;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_NOTE_OFF:
|
||||
chan[c.chan].active=false;
|
||||
chan[c.chan].keyOff=true;
|
||||
chan[c.chan].macroInit(NULL);
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF_ENV:
|
||||
case DIV_CMD_ENV_RELEASE:
|
||||
chan[c.chan].std.release();
|
||||
break;
|
||||
case DIV_CMD_INSTRUMENT:
|
||||
if (chan[c.chan].ins!=c.value || c.value2==1) {
|
||||
chan[c.chan].ins=c.value;
|
||||
chan[c.chan].insChanged=true;
|
||||
}
|
||||
break;
|
||||
case DIV_CMD_VOLUME:
|
||||
if (chan[c.chan].vol!=c.value) {
|
||||
chan[c.chan].vol=c.value;
|
||||
if (!chan[c.chan].std.vol.has) {
|
||||
chan[c.chan].outVol=c.value;
|
||||
if (chan[c.chan].active) {
|
||||
chan[c.chan].ctlChanged=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case DIV_CMD_GET_VOLUME:
|
||||
if (chan[c.chan].std.vol.has) {
|
||||
return chan[c.chan].vol;
|
||||
}
|
||||
return chan[c.chan].outVol;
|
||||
break;
|
||||
case DIV_CMD_PITCH:
|
||||
chan[c.chan].pitch=c.value;
|
||||
chan[c.chan].freqChanged=true;
|
||||
break;
|
||||
case DIV_CMD_WAVE:
|
||||
chan[c.chan].wave=c.value;
|
||||
chan[c.chan].ctlChanged=true;
|
||||
break;
|
||||
case DIV_CMD_STD_NOISE_MODE:
|
||||
audctl=c.value&0xff;
|
||||
audctlChanged=true;
|
||||
break;
|
||||
case DIV_CMD_NOTE_PORTA: {
|
||||
int destFreq=NOTE_PERIODIC(c.value2);
|
||||
bool return2=false;
|
||||
if (destFreq>chan[c.chan].baseFreq) {
|
||||
chan[c.chan].baseFreq+=c.value;
|
||||
if (chan[c.chan].baseFreq>=destFreq) {
|
||||
chan[c.chan].baseFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
} else {
|
||||
chan[c.chan].baseFreq-=c.value;
|
||||
if (chan[c.chan].baseFreq<=destFreq) {
|
||||
chan[c.chan].baseFreq=destFreq;
|
||||
return2=true;
|
||||
}
|
||||
}
|
||||
chan[c.chan].freqChanged=true;
|
||||
if (return2) {
|
||||
chan[c.chan].inPorta=false;
|
||||
return 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_LEGATO:
|
||||
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
||||
chan[c.chan].freqChanged=true;
|
||||
chan[c.chan].note=c.value;
|
||||
break;
|
||||
case DIV_CMD_PRE_PORTA:
|
||||
if (chan[c.chan].active && c.value2) {
|
||||
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_POKEY));
|
||||
}
|
||||
if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note);
|
||||
chan[c.chan].inPorta=c.value;
|
||||
break;
|
||||
case DIV_CMD_GET_VOLMAX:
|
||||
return 15;
|
||||
break;
|
||||
case DIV_CMD_MACRO_OFF:
|
||||
chan[c.chan].std.mask(c.value,true);
|
||||
break;
|
||||
case DIV_CMD_MACRO_ON:
|
||||
chan[c.chan].std.mask(c.value,false);
|
||||
break;
|
||||
case DIV_ALWAYS_SET_VOLUME:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::muteChannel(int ch, bool mute) {
|
||||
isMuted[ch]=mute;
|
||||
chan[ch].ctlChanged=true;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::forceIns() {
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].insChanged=true;
|
||||
chan[i].ctlChanged=true;
|
||||
chan[i].freqChanged=true;
|
||||
}
|
||||
audctlChanged=true;
|
||||
}
|
||||
|
||||
void* DivPlatformPOKEY::getChanState(int ch) {
|
||||
return &chan[ch];
|
||||
}
|
||||
|
||||
DivMacroInt* DivPlatformPOKEY::getChanMacroInt(int ch) {
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
DivDispatchOscBuffer* DivPlatformPOKEY::getOscBuffer(int ch) {
|
||||
return oscBuf[ch];
|
||||
}
|
||||
|
||||
unsigned char* DivPlatformPOKEY::getRegisterPool() {
|
||||
if (useAltASAP) {
|
||||
return const_cast<unsigned char*>(altASAP.getRegisterPool());
|
||||
} else {
|
||||
return regPool;
|
||||
}
|
||||
}
|
||||
|
||||
int DivPlatformPOKEY::getRegisterPoolSize() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::reset() {
|
||||
while (!writes.empty()) writes.pop();
|
||||
memset(regPool,0,16);
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i]=DivPlatformPOKEY::Channel();
|
||||
chan[i].std.setEngine(parent);
|
||||
}
|
||||
if (dumpWrites) {
|
||||
addWrite(0xffffffff,0);
|
||||
}
|
||||
|
||||
if (useAltASAP) {
|
||||
altASAP.reset();
|
||||
} else {
|
||||
ResetPokeyState(&pokey);
|
||||
}
|
||||
|
||||
audctl=0;
|
||||
audctlChanged=true;
|
||||
}
|
||||
|
||||
bool DivPlatformPOKEY::keyOffAffectsArp(int ch) {
|
||||
return true;
|
||||
}
|
||||
|
||||
float DivPlatformPOKEY::getPostAmp() {
|
||||
return 2.0f;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::notifyInsDeletion(void* ins) {
|
||||
for (int i=0; i<4; i++) {
|
||||
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::setFlags(const DivConfig& flags) {
|
||||
if (flags.getInt("clockSel",0)) {
|
||||
chipClock=COLOR_PAL*2.0/5.0;
|
||||
} else {
|
||||
chipClock=COLOR_NTSC/2.0;
|
||||
}
|
||||
CHECK_CUSTOM_CLOCK;
|
||||
|
||||
if (useAltASAP) {
|
||||
rate=chipClock/7;
|
||||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate/2;
|
||||
}
|
||||
altASAP.init(chipClock,rate);
|
||||
} else {
|
||||
rate=chipClock;
|
||||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate/14;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::poke(unsigned int addr, unsigned short val) {
|
||||
rWrite(addr,val);
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::poke(std::vector<DivRegWrite>& wlist) {
|
||||
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
||||
}
|
||||
|
||||
int DivPlatformPOKEY::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
||||
parent=p;
|
||||
dumpWrites=false;
|
||||
skipRegisterWrites=false;
|
||||
oscBufDelay=0;
|
||||
for (int i=0; i<4; i++) {
|
||||
isMuted[i]=false;
|
||||
oscBuf[i]=new DivDispatchOscBuffer;
|
||||
}
|
||||
|
||||
if (!useAltASAP) {
|
||||
MZPOKEYSND_Init(&pokey);
|
||||
}
|
||||
|
||||
setFlags(flags);
|
||||
reset();
|
||||
return 6;
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::quit() {
|
||||
for (int i=0; i<4; i++) {
|
||||
delete oscBuf[i];
|
||||
}
|
||||
}
|
||||
|
||||
void DivPlatformPOKEY::setAltASAP(bool value) {
|
||||
useAltASAP=value;
|
||||
}
|
||||
|
||||
DivPlatformPOKEY::~DivPlatformPOKEY() {
|
||||
}
|
||||
87
src/engine/platform/pokey.h
Normal file
87
src/engine/platform/pokey.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef _POKEY_H
|
||||
#define _POKEY_H
|
||||
|
||||
#include "../dispatch.h"
|
||||
#include <queue>
|
||||
|
||||
extern "C" {
|
||||
#include "sound/pokey/mzpokeysnd.h"
|
||||
}
|
||||
|
||||
#include "sound/pokey/AltASAP.hpp"
|
||||
|
||||
|
||||
class DivPlatformPOKEY: public DivDispatch {
|
||||
struct Channel: public SharedChannel<int> {
|
||||
unsigned char wave;
|
||||
bool ctlChanged;
|
||||
Channel():
|
||||
SharedChannel<int>(15),
|
||||
wave(5),
|
||||
ctlChanged(true) {}
|
||||
};
|
||||
Channel chan[4];
|
||||
DivDispatchOscBuffer* oscBuf[4];
|
||||
bool isMuted[4];
|
||||
struct QueuedWrite {
|
||||
unsigned char addr;
|
||||
unsigned char val;
|
||||
QueuedWrite(unsigned char a, unsigned char v): addr(a), val(v) {}
|
||||
};
|
||||
std::queue<QueuedWrite> writes;
|
||||
unsigned char audctl;
|
||||
bool audctlChanged;
|
||||
unsigned char oscBufDelay;
|
||||
PokeyState pokey;
|
||||
AltASAP::Pokey altASAP;
|
||||
bool useAltASAP;
|
||||
unsigned char regPool[16];
|
||||
friend void putDispatchChip(void*,int);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
public:
|
||||
void acquire(short* bufL, short* bufR, size_t start, size_t len);
|
||||
void acquireMZ(short* buf, size_t start, size_t len);
|
||||
void acquireASAP(short* buf, size_t start, size_t len);
|
||||
int dispatch(DivCommand c);
|
||||
void* getChanState(int chan);
|
||||
DivMacroInt* getChanMacroInt(int ch);
|
||||
DivDispatchOscBuffer* getOscBuffer(int chan);
|
||||
unsigned char* getRegisterPool();
|
||||
int getRegisterPoolSize();
|
||||
void reset();
|
||||
void forceIns();
|
||||
void tick(bool sysTick=true);
|
||||
void muteChannel(int ch, bool mute);
|
||||
bool keyOffAffectsArp(int ch);
|
||||
float getPostAmp();
|
||||
void setFlags(const DivConfig& flags);
|
||||
void notifyInsDeletion(void* ins);
|
||||
void poke(unsigned int addr, unsigned short val);
|
||||
void poke(std::vector<DivRegWrite>& wlist);
|
||||
const char** getRegisterSheet();
|
||||
int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags);
|
||||
void quit();
|
||||
void setAltASAP(bool useAltASAP);
|
||||
~DivPlatformPOKEY();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -61,6 +61,11 @@ void DivPlatformRF5C68::acquire(short* bufL, short* bufR, size_t start, size_t l
|
|||
buf[8],buf[9],buf[10],buf[11],buf[12],buf[13],buf[14],buf[15]
|
||||
};
|
||||
size_t pos=start;
|
||||
|
||||
for (int i=0; i<16; i++) {
|
||||
memset(buf[i],0,256*sizeof(short));
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
size_t blockLen=MIN(len,256);
|
||||
short* bufPtrs[2]={&bufL[pos],&bufR[pos]};
|
||||
|
|
|
|||
|
|
@ -96,24 +96,16 @@ void DivPlatformSegaPCM::tick(bool sysTick) {
|
|||
}
|
||||
|
||||
if (parent->song.newSegaPCM) if (chan[i].std.panL.had) {
|
||||
if (chan[i].isNewSegaPCM) {
|
||||
chan[i].chPanL=chan[i].std.panL.val&127;
|
||||
chan[i].chVolL=(chan[i].outVol*chan[i].chPanL)/127;
|
||||
} else {
|
||||
chan[i].chVolL=chan[i].std.panL.val&127;
|
||||
}
|
||||
chan[i].chPanL=chan[i].std.panL.val&127;
|
||||
chan[i].chVolL=(chan[i].outVol*chan[i].chPanL)/127;
|
||||
if (dumpWrites) {
|
||||
addWrite(0x10002+(i<<3),chan[i].chVolL);
|
||||
}
|
||||
}
|
||||
|
||||
if (parent->song.newSegaPCM) if (chan[i].std.panR.had) {
|
||||
if (chan[i].isNewSegaPCM) {
|
||||
chan[i].chPanR=chan[i].std.panR.val&127;
|
||||
chan[i].chVolR=(chan[i].outVol*chan[i].chPanR)/127;
|
||||
} else {
|
||||
chan[i].chVolR=chan[i].std.panR.val&127;
|
||||
}
|
||||
chan[i].chPanR=chan[i].std.panR.val&127;
|
||||
chan[i].chVolR=(chan[i].outVol*chan[i].chPanR)/127;
|
||||
if (dumpWrites) {
|
||||
addWrite(0x10003+(i<<3),chan[i].chVolR);
|
||||
}
|
||||
|
|
@ -287,7 +279,7 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) {
|
|||
if (!chan[c.chan].std.vol.has) {
|
||||
chan[c.chan].outVol=c.value;
|
||||
}
|
||||
if (parent->song.newSegaPCM && chan[c.chan].isNewSegaPCM) {
|
||||
if (parent->song.newSegaPCM) {
|
||||
chan[c.chan].chVolL=(c.value*chan[c.chan].chPanL)/127;
|
||||
chan[c.chan].chVolR=(c.value*chan[c.chan].chPanR)/127;
|
||||
} else {
|
||||
|
|
@ -311,7 +303,7 @@ int DivPlatformSegaPCM::dispatch(DivCommand c) {
|
|||
chan[c.chan].ins=c.value;
|
||||
break;
|
||||
case DIV_CMD_PANNING: {
|
||||
if (parent->song.newSegaPCM && chan[c.chan].isNewSegaPCM) {
|
||||
if (parent->song.newSegaPCM) {
|
||||
chan[c.chan].chPanL=c.value>>1;
|
||||
chan[c.chan].chPanR=c.value2>>1;
|
||||
chan[c.chan].chVolL=(chan[c.chan].outVol*chan[c.chan].chPanL)/127;
|
||||
|
|
|
|||
653
src/engine/platform/sound/pokey/AltASAP.cpp
Normal file
653
src/engine/platform/sound/pokey/AltASAP.cpp
Normal file
|
|
@ -0,0 +1,653 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2022 tildearrow and contributors
|
||||
*
|
||||
* Original author: Piotr Fusik (http://asap.sourceforge.net)
|
||||
* Rewritten based on Mikey emulation by Waldemar Pawlaszek
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "AltASAP.hpp"
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <cassert>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
namespace AltASAP
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static constexpr int64_t CNT_MAX = std::numeric_limits<int64_t>::max() & ~7;
|
||||
static constexpr int MuteFrequency = 1;
|
||||
static constexpr int MuteInit = 2;
|
||||
static constexpr int MuteSerialInput = 8;
|
||||
//just some magick value to match the audio level of mzpokeysnd
|
||||
static constexpr int16_t MAGICK_VOLUME_BOOSTER = 160;
|
||||
static constexpr int16_t MAGICK_OSC_VOLUME_BOOSTER = 4;
|
||||
|
||||
struct PokeyBase
|
||||
{
|
||||
int64_t mPolyIndex;
|
||||
int mAudctl;
|
||||
int mSkctl;
|
||||
bool mInit;
|
||||
std::array<uint8_t, 511> mPoly9Lookup;
|
||||
std::array<uint8_t, 16385> mPoly17Lookup;
|
||||
|
||||
|
||||
PokeyBase() : mPolyIndex{ 15 * 31 * 131071 }, mAudctl{ 0 }, mSkctl{ 3 }, mInit{ false }, mPoly9Lookup{}, mPoly17Lookup{}
|
||||
{
|
||||
int reg = 0x1ff;
|
||||
for ( int i = 0; i < 511; i++ )
|
||||
{
|
||||
reg = ( ( ( reg >> 5 ^ reg ) & 1 ) << 8 ) + ( reg >> 1 );
|
||||
mPoly9Lookup[i] = reg & 0xff;
|
||||
}
|
||||
reg = 0x1ffff;
|
||||
for ( int i = 0; i < 16385; i++ )
|
||||
{
|
||||
reg = ( ( ( reg >> 5 ^ reg ) & 0xff ) << 9 ) + ( reg >> 8 );
|
||||
mPoly17Lookup[i] = reg >> 1 & 0xff;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
"Queue" holding event timepoints.
|
||||
- 4 channel timer fire points
|
||||
- 1 sample point
|
||||
Three LSBs are used to encode event kind: 0-3 are channels, 4 is sampling.
|
||||
Channel sequence is 2,3,0,1
|
||||
*/
|
||||
class ActionQueue
|
||||
{
|
||||
public:
|
||||
|
||||
ActionQueue() : mTab{ CNT_MAX | 0, CNT_MAX | 1, CNT_MAX | 2, CNT_MAX | 3, CNT_MAX | 4 }
|
||||
{
|
||||
}
|
||||
|
||||
void insert( int idx, int64_t value )
|
||||
{
|
||||
assert( idx < (int)mTab.size() );
|
||||
idx ^= 2;
|
||||
mTab[idx] = value | idx;
|
||||
}
|
||||
|
||||
void insertSampling( int64_t value )
|
||||
{
|
||||
mTab[4] = value | 4;
|
||||
}
|
||||
|
||||
void disable( int idx )
|
||||
{
|
||||
assert( idx < (int)mTab.size() );
|
||||
idx ^= 2;
|
||||
mTab[idx] = CNT_MAX | idx;
|
||||
}
|
||||
|
||||
bool enqueued( int idx )
|
||||
{
|
||||
assert( idx < (int)mTab.size() );
|
||||
idx ^= 2;
|
||||
return mTab[idx] < CNT_MAX;
|
||||
}
|
||||
|
||||
int64_t pop()
|
||||
{
|
||||
int64_t min1 = std::min( mTab[0], mTab[1] );
|
||||
int64_t min2 = std::min( mTab[2], mTab[3] );
|
||||
int64_t min3 = std::min( min1, mTab[4] );
|
||||
int64_t min4 = std::min( min2, min3 );
|
||||
|
||||
return min4 ^ 2;
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<int64_t, 5> mTab;
|
||||
};
|
||||
|
||||
class AudioChannel
|
||||
{
|
||||
public:
|
||||
AudioChannel( ActionQueue& queue, uint32_t number ) : mQueue{ queue }, mNumber{ number }, mAudf{ 0 }, mAudc{ 0 }, mPeriodCycles{ 28 }, mMute{ MuteFrequency }, mDelta{ 0 }, mOut{ 0 }
|
||||
{
|
||||
}
|
||||
|
||||
int16_t getOutput() const
|
||||
{
|
||||
return (int16_t)mDelta;
|
||||
}
|
||||
|
||||
void fillRegisterPool( uint8_t* regs )
|
||||
{
|
||||
regs[0] = (uint8_t)mAudf;
|
||||
regs[1] = (uint8_t)mAudc;
|
||||
}
|
||||
|
||||
void renewTrigger( int64_t cycle )
|
||||
{
|
||||
overrideTrigger( cycle + mPeriodCycles );
|
||||
}
|
||||
|
||||
void overrideTrigger( int64_t cycle )
|
||||
{
|
||||
mQueue.insert( mNumber, cycle << 3 );
|
||||
}
|
||||
|
||||
void doStimer( int64_t cycle )
|
||||
{
|
||||
if ( mQueue.enqueued( mNumber ) )
|
||||
renewTrigger( cycle );
|
||||
}
|
||||
|
||||
void trigger( int64_t cycle, PokeyBase const& pokey )
|
||||
{
|
||||
renewTrigger( cycle );
|
||||
if ( ( mAudc & 0xb0 ) == 0xa0 )
|
||||
mOut ^= 1;
|
||||
else if ( ( mAudc & 0x10 ) != 0 || pokey.mInit )
|
||||
return;
|
||||
else
|
||||
{
|
||||
int64_t poly = cycle + pokey.mPolyIndex - mNumber;
|
||||
if ( mAudc < 0x80 && ( 0x65bd44e0 & 1 << ( poly % 31 ) ) == 0 ) // 0000011100100010101111011010011
|
||||
return;
|
||||
if ( ( mAudc & 0x20 ) != 0 )
|
||||
mOut ^= 1;
|
||||
else
|
||||
{
|
||||
uint32_t newOut;
|
||||
if ( ( mAudc & 0x40 ) != 0 )
|
||||
newOut = 0x5370u >> (int)( poly % 15 ); // 000011101100101
|
||||
else if ( pokey.mAudctl < 0x80 )
|
||||
{
|
||||
poly %= 131071;
|
||||
newOut = pokey.mPoly17Lookup[poly >> 3] >> ( poly & 7 );
|
||||
}
|
||||
else
|
||||
newOut = pokey.mPoly9Lookup[poly % 511];
|
||||
newOut &= 1;
|
||||
if ( mOut == newOut )
|
||||
return;
|
||||
mOut = newOut;
|
||||
}
|
||||
}
|
||||
toggle();
|
||||
}
|
||||
|
||||
uint32_t mute() const
|
||||
{
|
||||
return mMute;
|
||||
}
|
||||
|
||||
uint32_t audf() const
|
||||
{
|
||||
return mAudf;
|
||||
}
|
||||
|
||||
uint32_t audc() const
|
||||
{
|
||||
return mAudc;
|
||||
}
|
||||
|
||||
void setAudf( uint32_t value )
|
||||
{
|
||||
mAudf = value;
|
||||
}
|
||||
|
||||
void setAudc( int64_t cycle, uint32_t value )
|
||||
{
|
||||
if ( mAudc == value )
|
||||
return;
|
||||
mAudc = value;
|
||||
int32_t volume = value & 0x0f;
|
||||
if ( ( value & 0x10 ) != 0 )
|
||||
{
|
||||
mDelta = volume * MAGICK_VOLUME_BOOSTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
muteUltrasound( cycle );
|
||||
if ( mDelta > 0 )
|
||||
mDelta = volume * MAGICK_VOLUME_BOOSTER;
|
||||
else
|
||||
mDelta = -volume * MAGICK_VOLUME_BOOSTER;
|
||||
}
|
||||
}
|
||||
|
||||
void toggle()
|
||||
{
|
||||
mDelta = -mDelta;
|
||||
}
|
||||
|
||||
void setPeriodCycles( int64_t value )
|
||||
{
|
||||
mPeriodCycles = value;
|
||||
}
|
||||
|
||||
void setMute( bool enable, int mask, int64_t cycle )
|
||||
{
|
||||
if ( enable )
|
||||
{
|
||||
mMute |= mask;
|
||||
mQueue.disable( mNumber );
|
||||
}
|
||||
else
|
||||
{
|
||||
mMute &= ~mask;
|
||||
if ( mMute == 0 && !mQueue.enqueued( mNumber ) )
|
||||
overrideTrigger( cycle );
|
||||
}
|
||||
}
|
||||
|
||||
void muteUltrasound( int64_t cycle )
|
||||
{
|
||||
static constexpr int UltrasoundCycles = 112;
|
||||
setMute( mPeriodCycles <= UltrasoundCycles && ( mAudc & 0xb0 ) == 0xa0, MuteFrequency, cycle );
|
||||
}
|
||||
|
||||
private:
|
||||
ActionQueue& mQueue;
|
||||
uint32_t mNumber;
|
||||
uint32_t mAudf;
|
||||
uint32_t mAudc;
|
||||
int64_t mPeriodCycles;
|
||||
|
||||
uint32_t mMute;
|
||||
int32_t mDelta;
|
||||
uint32_t mOut;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
class PokeyPimpl : public PokeyBase
|
||||
{
|
||||
public:
|
||||
|
||||
PokeyPimpl( uint32_t pokeyClock, uint32_t sampleRate ) : PokeyBase{}, mQueue{ std::make_unique<ActionQueue>() },
|
||||
mAudioChannels{ AudioChannel{ *mQueue, 0u }, AudioChannel{ *mQueue, 1u }, AudioChannel{ *mQueue, 2u }, AudioChannel{ *mQueue, 3u } },
|
||||
mRegisterPool{}, mTick{}, mNextTick{},
|
||||
mReloadCycles1{ 28 }, mReloadCycles3{ 28 }, mDivCycles{ 28 }, mSampleRate{ sampleRate }, mSamplesRemainder{},
|
||||
mTicksPerSample{ ( pokeyClock * 8 ) / mSampleRate, ( pokeyClock * 8 ) % mSampleRate }
|
||||
{
|
||||
std::fill_n( mRegisterPool.data(), mRegisterPool.size(), (uint8_t)0xff );
|
||||
enqueueSampling();
|
||||
}
|
||||
|
||||
~PokeyPimpl() {}
|
||||
|
||||
void write( uint8_t address, uint8_t value )
|
||||
{
|
||||
auto cycle = mTick >> 3;
|
||||
|
||||
switch ( address & 0xf )
|
||||
{
|
||||
case 0x00:
|
||||
if ( value == mAudioChannels[0].audf() )
|
||||
break;
|
||||
mAudioChannels[0].setAudf( value );
|
||||
switch ( mAudctl & 0x50 )
|
||||
{
|
||||
case 0x00:
|
||||
mAudioChannels[0].setPeriodCycles( mDivCycles * ( value + 1 ) );
|
||||
break;
|
||||
case 0x10:
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( value + ( mAudioChannels[1].audf() << 8 ) + 1 ) );
|
||||
mReloadCycles1 = mDivCycles * ( value + 1 );
|
||||
mAudioChannels[1].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x40:
|
||||
mAudioChannels[0].setPeriodCycles( value + 4 );
|
||||
break;
|
||||
case 0x50:
|
||||
mAudioChannels[1].setPeriodCycles( value + ( mAudioChannels[1].audf() << 8 ) + 7 );
|
||||
mReloadCycles1 = value + 4;
|
||||
mAudioChannels[1].muteUltrasound( cycle );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[0].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x01:
|
||||
mAudioChannels[0].setAudc( cycle, value );
|
||||
break;
|
||||
case 0x02:
|
||||
if ( value == mAudioChannels[1].audf() )
|
||||
break;
|
||||
mAudioChannels[1].setAudf( value );
|
||||
switch ( mAudctl & 0x50 )
|
||||
{
|
||||
case 0x00:
|
||||
case 0x40:
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( value + 1 ) );
|
||||
break;
|
||||
case 0x10:
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( mAudioChannels[0].audf() + ( value << 8 ) + 1 ) );
|
||||
break;
|
||||
case 0x50:
|
||||
mAudioChannels[1].setPeriodCycles( mAudioChannels[0].audf() + ( value << 8 ) + 7 );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[1].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x03:
|
||||
mAudioChannels[1].setAudc( cycle, value );
|
||||
break;
|
||||
case 0x04:
|
||||
if ( value == mAudioChannels[2].audf() )
|
||||
break;
|
||||
mAudioChannels[2].setAudf( value );
|
||||
switch ( mAudctl & 0x28 )
|
||||
{
|
||||
case 0x00:
|
||||
mAudioChannels[2].setPeriodCycles( mDivCycles * ( value + 1 ) );
|
||||
break;
|
||||
case 0x08:
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( value + ( mAudioChannels[3].audf() << 8 ) + 1 ) );
|
||||
mReloadCycles3 = mDivCycles * ( value + 1 );
|
||||
mAudioChannels[3].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x20:
|
||||
mAudioChannels[2].setPeriodCycles( value + 4 );
|
||||
break;
|
||||
case 0x28:
|
||||
mAudioChannels[3].setPeriodCycles( value + ( mAudioChannels[3].audf() << 8 ) + 7 );
|
||||
mReloadCycles3 = value + 4;
|
||||
mAudioChannels[3].muteUltrasound( cycle );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[2].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x05:
|
||||
mAudioChannels[2].setAudc( cycle, value );
|
||||
break;
|
||||
case 0x06:
|
||||
if ( value == mAudioChannels[3].audf() )
|
||||
break;
|
||||
mAudioChannels[3].setAudf( value );
|
||||
switch ( mAudctl & 0x28 )
|
||||
{
|
||||
case 0x00:
|
||||
case 0x20:
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( value + 1 ) );
|
||||
break;
|
||||
case 0x08:
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( mAudioChannels[2].audf() + ( value << 8 ) + 1 ) );
|
||||
break;
|
||||
case 0x28:
|
||||
mAudioChannels[3].setPeriodCycles( mAudioChannels[2].audf() + ( value << 8 ) + 7 );
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[3].muteUltrasound( cycle );
|
||||
break;
|
||||
case 0x07:
|
||||
mAudioChannels[3].setAudc( cycle, value );
|
||||
break;
|
||||
case 0x08:
|
||||
if ( value == mAudctl )
|
||||
break;
|
||||
mAudctl = value;
|
||||
mDivCycles = ( value & 1 ) != 0 ? 114 : 28;
|
||||
switch ( value & 0x50 )
|
||||
{
|
||||
case 0x00:
|
||||
mAudioChannels[0].setPeriodCycles( mDivCycles * ( mAudioChannels[0].audf() + 1 ) );
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( mAudioChannels[1].audf() + 1 ) );
|
||||
break;
|
||||
case 0x10:
|
||||
mAudioChannels[0].setPeriodCycles( (int64_t)mDivCycles << 8 );
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( mAudioChannels[0].audf() + ( mAudioChannels[1].audf() << 8 ) + 1 ) );
|
||||
mReloadCycles1 = mDivCycles * ( mAudioChannels[0].audf() + 1 );
|
||||
break;
|
||||
case 0x40:
|
||||
mAudioChannels[0].setPeriodCycles( mAudioChannels[0].audf() + 4 );
|
||||
mAudioChannels[1].setPeriodCycles( mDivCycles * ( mAudioChannels[1].audf() + 1 ) );
|
||||
break;
|
||||
case 0x50:
|
||||
mAudioChannels[0].setPeriodCycles( 256 );
|
||||
mAudioChannels[1].setPeriodCycles( mAudioChannels[0].audf() + ( mAudioChannels[1].audf() << 8 ) + 7 );
|
||||
mReloadCycles1 = mAudioChannels[0].audf() + 4;
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[0].muteUltrasound( cycle );
|
||||
mAudioChannels[1].muteUltrasound( cycle );
|
||||
switch ( value & 0x28 )
|
||||
{
|
||||
case 0x00:
|
||||
mAudioChannels[2].setPeriodCycles( mDivCycles * ( mAudioChannels[2].audf() + 1 ) );
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( mAudioChannels[3].audf() + 1 ) );
|
||||
break;
|
||||
case 0x08:
|
||||
mAudioChannels[2].setPeriodCycles( (int64_t)mDivCycles << 8 );
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( mAudioChannels[2].audf() + ( mAudioChannels[3].audf() << 8 ) + 1 ) );
|
||||
mReloadCycles3 = mDivCycles * ( mAudioChannels[2].audf() + 1 );
|
||||
break;
|
||||
case 0x20:
|
||||
mAudioChannels[2].setPeriodCycles( mAudioChannels[2].audf() + 4 );
|
||||
mAudioChannels[3].setPeriodCycles( mDivCycles * ( mAudioChannels[3].audf() + 1 ) );
|
||||
break;
|
||||
case 0x28:
|
||||
mAudioChannels[2].setPeriodCycles( 256 );
|
||||
mAudioChannels[3].setPeriodCycles( mAudioChannels[2].audf() + ( mAudioChannels[3].audf() << 8 ) + 7 );
|
||||
mReloadCycles3 = mAudioChannels[2].audf() + 4;
|
||||
break;
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
mAudioChannels[2].muteUltrasound( cycle );
|
||||
mAudioChannels[3].muteUltrasound( cycle );
|
||||
initMute( cycle );
|
||||
break;
|
||||
case 0x09:
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
mAudioChannels[i].doStimer( cycle );
|
||||
break;
|
||||
case 0x0f:
|
||||
{
|
||||
if ( value == mSkctl )
|
||||
break;
|
||||
mSkctl = value;
|
||||
bool init = ( value & 3 ) == 0;
|
||||
if ( mInit && !init )
|
||||
mPolyIndex = ( ( mAudctl & 0x80 ) != 0 ? 15 * 31 * 511 - 1 : 15 * 31 * 131071 - 1 ) - cycle;
|
||||
mInit = init;
|
||||
initMute( cycle );
|
||||
mAudioChannels[2].setMute( ( value & 0x10 ) != 0, MuteSerialInput, cycle );
|
||||
mAudioChannels[3].setMute( ( value & 0x10 ) != 0, MuteSerialInput, cycle );
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int16_t sampleAudio( DivDispatchOscBuffer** oscb )
|
||||
{
|
||||
for ( ;; )
|
||||
{
|
||||
int64_t value = mQueue->pop();
|
||||
if ( ( value & 7 ) == 6 ) // 6 == 4 ^ 2
|
||||
{
|
||||
int16_t ch0 = mAudioChannels[0].getOutput();
|
||||
int16_t ch1 = mAudioChannels[1].getOutput();
|
||||
int16_t ch2 = mAudioChannels[2].getOutput();
|
||||
int16_t ch3 = mAudioChannels[3].getOutput();
|
||||
|
||||
if ( oscb != nullptr )
|
||||
{
|
||||
oscb[0]->data[oscb[0]->needle++]=ch0 * MAGICK_OSC_VOLUME_BOOSTER;
|
||||
oscb[1]->data[oscb[1]->needle++]=ch1 * MAGICK_OSC_VOLUME_BOOSTER;
|
||||
oscb[2]->data[oscb[2]->needle++]=ch2 * MAGICK_OSC_VOLUME_BOOSTER;
|
||||
oscb[3]->data[oscb[3]->needle++]=ch3 * MAGICK_OSC_VOLUME_BOOSTER;
|
||||
}
|
||||
|
||||
enqueueSampling();
|
||||
return ch0 + ch1 + ch2 + ch3;
|
||||
}
|
||||
else
|
||||
{
|
||||
fireTimer( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t const* getRegisterPool()
|
||||
{
|
||||
for ( size_t i = 0; i < mAudioChannels.size(); ++i )
|
||||
{
|
||||
mAudioChannels[i].fillRegisterPool( mRegisterPool.data() + 2 * i );
|
||||
}
|
||||
|
||||
mRegisterPool[8] = mAudctl;
|
||||
|
||||
return mRegisterPool.data();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void initMute( int64_t cycle )
|
||||
{
|
||||
mAudioChannels[0].setMute( mInit && ( mAudctl & 0x40 ) == 0, MuteInit, cycle );
|
||||
mAudioChannels[1].setMute( mInit && ( mAudctl & 0x50 ) != 0x50, MuteInit, cycle );
|
||||
mAudioChannels[2].setMute( mInit && ( mAudctl & 0x20 ) == 0, MuteInit, cycle );
|
||||
mAudioChannels[3].setMute( mInit && ( mAudctl & 0x28 ) != 0x28, MuteInit, cycle );
|
||||
}
|
||||
|
||||
void fireTimer( int64_t tick )
|
||||
{
|
||||
mTick = tick & ~7;
|
||||
size_t ch = tick & 3;
|
||||
auto cycle = tick >> 3;
|
||||
|
||||
switch ( ch )
|
||||
{
|
||||
case 0:
|
||||
if ( ( mSkctl & 0x88 ) == 8 ) // two-tone, sending 1 (i.e. timer1)
|
||||
mAudioChannels[1].renewTrigger( cycle );
|
||||
mAudioChannels[0].trigger( cycle, *this );
|
||||
break;
|
||||
case 1:
|
||||
if ( ( mAudctl & 0x10 ) != 0 )
|
||||
mAudioChannels[0].overrideTrigger( cycle + mReloadCycles1 );
|
||||
else if ( ( mSkctl & 8 ) != 0 ) // two-tone
|
||||
mAudioChannels[0].renewTrigger( cycle );
|
||||
mAudioChannels[1].trigger( cycle, *this );
|
||||
break;
|
||||
case 2:
|
||||
if ( ( mAudctl & 4 ) != 0 && mAudioChannels[0].getOutput() > 0 && mAudioChannels[0].mute() == 0 )
|
||||
mAudioChannels[0].toggle();
|
||||
mAudioChannels[2].trigger( cycle, *this );
|
||||
break;
|
||||
case 3:
|
||||
if ( ( mAudctl & 8 ) != 0 )
|
||||
mAudioChannels[2].overrideTrigger( cycle + mReloadCycles3 );
|
||||
if ( ( mAudctl & 2 ) != 0 && mAudioChannels[1].getOutput() > 0 && mAudioChannels[1].mute() == 0 )
|
||||
mAudioChannels[1].toggle();
|
||||
mAudioChannels[3].trigger( cycle, *this );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void enqueueSampling()
|
||||
{
|
||||
mTick = mNextTick & ~7;
|
||||
mNextTick = mNextTick + mTicksPerSample.first;
|
||||
mSamplesRemainder += mTicksPerSample.second;
|
||||
if ( mSamplesRemainder > mSampleRate )
|
||||
{
|
||||
mSamplesRemainder %= mSampleRate;
|
||||
mNextTick += 1;
|
||||
}
|
||||
|
||||
mQueue->insertSampling( mNextTick & ~7 );
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<ActionQueue> mQueue;
|
||||
std::array<AudioChannel, 4> mAudioChannels;
|
||||
|
||||
std::array<uint8_t, 4 * 2 + 1> mRegisterPool;
|
||||
|
||||
uint64_t mTick;
|
||||
uint64_t mNextTick;
|
||||
int64_t mReloadCycles1;
|
||||
int64_t mReloadCycles3;
|
||||
int64_t mDivCycles;
|
||||
uint32_t mSampleRate;
|
||||
uint32_t mSamplesRemainder;
|
||||
std::pair<uint32_t, uint32_t> mTicksPerSample;
|
||||
};
|
||||
|
||||
//Initializing periods with safe defaults
|
||||
Pokey::Pokey() : mPokeyClock{ (uint32_t)COLOR_NTSC / 2 }, mSampleRate{ mPokeyClock / 7 }, mPokey{}
|
||||
{
|
||||
}
|
||||
|
||||
void Pokey::init( uint32_t pokeyClock, uint32_t sampleRate )
|
||||
{
|
||||
mPokey.reset();
|
||||
mPokeyClock = pokeyClock;
|
||||
mSampleRate = sampleRate;
|
||||
}
|
||||
|
||||
void Pokey::reset()
|
||||
{
|
||||
mPokey = std::make_unique<PokeyPimpl>( mPokeyClock, mSampleRate );
|
||||
}
|
||||
|
||||
Pokey::~Pokey()
|
||||
{
|
||||
}
|
||||
|
||||
void Pokey::write( uint8_t address, uint8_t value )
|
||||
{
|
||||
assert( mPokey );
|
||||
mPokey->write( address, value );
|
||||
}
|
||||
|
||||
int16_t Pokey::sampleAudio( DivDispatchOscBuffer** oscb )
|
||||
{
|
||||
assert( mPokey );
|
||||
return mPokey->sampleAudio( oscb );
|
||||
}
|
||||
|
||||
uint8_t const* Pokey::getRegisterPool()
|
||||
{
|
||||
assert( mPokey );
|
||||
return mPokey->getRegisterPool();
|
||||
}
|
||||
|
||||
}
|
||||
35
src/engine/platform/sound/pokey/AltASAP.hpp
Normal file
35
src/engine/platform/sound/pokey/AltASAP.hpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
// can you forgive me
|
||||
#include "../../../dispatch.h"
|
||||
|
||||
namespace AltASAP
|
||||
{
|
||||
|
||||
class PokeyPimpl;
|
||||
|
||||
class Pokey
|
||||
{
|
||||
public:
|
||||
|
||||
Pokey();
|
||||
void init( uint32_t pokeyClock, uint32_t sampleRate );
|
||||
~Pokey();
|
||||
|
||||
void write( uint8_t address, uint8_t value );
|
||||
int16_t sampleAudio( DivDispatchOscBuffer** oscb = nullptr );
|
||||
|
||||
uint8_t const* getRegisterPool();
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
uint32_t mPokeyClock;
|
||||
uint32_t mSampleRate;
|
||||
std::unique_ptr<PokeyPimpl> mPokey;
|
||||
};
|
||||
|
||||
}
|
||||
1655
src/engine/platform/sound/pokey/mzpokeysnd.c
Normal file
1655
src/engine/platform/sound/pokey/mzpokeysnd.c
Normal file
File diff suppressed because it is too large
Load diff
159
src/engine/platform/sound/pokey/mzpokeysnd.h
Normal file
159
src/engine/platform/sound/pokey/mzpokeysnd.h
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
#ifndef MZPOKEYSND_H_
|
||||
#define MZPOKEYSND_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
struct stPokeyState;
|
||||
|
||||
typedef int (*readout_t)(struct stPokeyState* ps);
|
||||
typedef void (*event_t)(struct stPokeyState* ps, int p5v, int p4v, int p917v);
|
||||
|
||||
#ifdef NONLINEAR_MIXING
|
||||
/* Change queue event value type */
|
||||
typedef double qev_t;
|
||||
#else
|
||||
typedef unsigned char qev_t;
|
||||
#endif
|
||||
|
||||
/* State variables for single Pokey Chip */
|
||||
typedef struct stPokeyState
|
||||
{
|
||||
int curtick;
|
||||
/* Poly positions */
|
||||
int poly4pos;
|
||||
int poly5pos;
|
||||
int poly17pos;
|
||||
int poly9pos;
|
||||
|
||||
/* Main divider (64khz/15khz) */
|
||||
int mdivk; /* 28 for 64khz, 114 for 15khz */
|
||||
|
||||
/* Main switches */
|
||||
int selpoly9;
|
||||
int c0_hf;
|
||||
int c1_f0;
|
||||
int c2_hf;
|
||||
int c3_f2;
|
||||
|
||||
/* SKCTL for two-tone mode */
|
||||
int skctl;
|
||||
|
||||
/* Main output state */
|
||||
qev_t outvol_all;
|
||||
int forcero; /* Force readout */
|
||||
|
||||
/* channel 0 state */
|
||||
|
||||
readout_t readout_0;
|
||||
event_t event_0;
|
||||
|
||||
int c0divpos;
|
||||
int c0divstart; /* AUDF0 recalculated */
|
||||
int c0divstart_p; /* start value when c1_f0 */
|
||||
int c0diva; /* AUDF0 register */
|
||||
|
||||
int c0t1; /* D - 5bit, Q goes to sw3 */
|
||||
int c0t2; /* D - out sw2, Q goes to sw4 and t3 */
|
||||
int c0t3; /* D - out t2, q goes to xor */
|
||||
|
||||
int c0sw1; /* in1 - 4bit, in2 - 17bit, out goes to sw2 */
|
||||
int c0sw2; /* in1 - /Q t2, in2 - out sw1, out goes to t2 */
|
||||
int c0sw3; /* in1 - +5, in2 - Q t1, out goes to C t2 */
|
||||
int c0sw4; /* hi-pass sw */
|
||||
int c0vo; /* volume only */
|
||||
|
||||
#ifndef NONLINEAR_MIXING
|
||||
int c0stop; /* channel counter stopped */
|
||||
#endif
|
||||
|
||||
int vol0;
|
||||
|
||||
int outvol_0;
|
||||
|
||||
/* channel 1 state */
|
||||
|
||||
readout_t readout_1;
|
||||
event_t event_1;
|
||||
|
||||
int c1divpos;
|
||||
int c1divstart;
|
||||
int c1diva;
|
||||
|
||||
int c1t1;
|
||||
int c1t2;
|
||||
int c1t3;
|
||||
|
||||
int c1sw1;
|
||||
int c1sw2;
|
||||
int c1sw3;
|
||||
int c1sw4;
|
||||
int c1vo;
|
||||
|
||||
#ifndef NONLINEAR_MIXING
|
||||
int c1stop; /* channel counter stopped */
|
||||
#endif
|
||||
|
||||
int vol1;
|
||||
|
||||
int outvol_1;
|
||||
|
||||
/* channel 2 state */
|
||||
|
||||
readout_t readout_2;
|
||||
event_t event_2;
|
||||
|
||||
int c2divpos;
|
||||
int c2divstart;
|
||||
int c2divstart_p; /* start value when c1_f0 */
|
||||
int c2diva;
|
||||
|
||||
int c2t1;
|
||||
int c2t2;
|
||||
|
||||
int c2sw1;
|
||||
int c2sw2;
|
||||
int c2sw3;
|
||||
int c2vo;
|
||||
|
||||
#ifndef NONLINEAR_MIXING
|
||||
int c2stop; /* channel counter stopped */
|
||||
#endif
|
||||
|
||||
int vol2;
|
||||
|
||||
int outvol_2;
|
||||
|
||||
/* channel 3 state */
|
||||
|
||||
readout_t readout_3;
|
||||
event_t event_3;
|
||||
|
||||
int c3divpos;
|
||||
int c3divstart;
|
||||
int c3diva;
|
||||
|
||||
int c3t1;
|
||||
int c3t2;
|
||||
|
||||
int c3sw1;
|
||||
int c3sw2;
|
||||
int c3sw3;
|
||||
int c3vo;
|
||||
|
||||
#ifndef NONLINEAR_MIXING
|
||||
int c3stop; /* channel counter stopped */
|
||||
#endif
|
||||
|
||||
int vol3;
|
||||
|
||||
int outvol_3;
|
||||
} PokeyState;
|
||||
|
||||
void mzpokeysnd_process_16(PokeyState* ps, void* sndbuffer, int sndn);
|
||||
void Update_pokey_sound_mz(PokeyState* ps, unsigned short addr, unsigned char val, unsigned char gain);
|
||||
|
||||
void ResetPokeyState(PokeyState* ps);
|
||||
|
||||
int MZPOKEYSND_Init(PokeyState* ps);
|
||||
|
||||
#endif /* MZPOKEYSND_H_ */
|
||||
78
src/engine/platform/sound/pokey/pokey.h
Normal file
78
src/engine/platform/sound/pokey/pokey.h
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#ifndef POKEY_H_
|
||||
#define POKEY_H_
|
||||
|
||||
#define POKEY_OFFSET_AUDF1 0x00
|
||||
#define POKEY_OFFSET_AUDC1 0x01
|
||||
#define POKEY_OFFSET_AUDF2 0x02
|
||||
#define POKEY_OFFSET_AUDC2 0x03
|
||||
#define POKEY_OFFSET_AUDF3 0x04
|
||||
#define POKEY_OFFSET_AUDC3 0x05
|
||||
#define POKEY_OFFSET_AUDF4 0x06
|
||||
#define POKEY_OFFSET_AUDC4 0x07
|
||||
#define POKEY_OFFSET_AUDCTL 0x08
|
||||
#define POKEY_OFFSET_STIMER 0x09
|
||||
#define POKEY_OFFSET_SKRES 0x0a
|
||||
#define POKEY_OFFSET_POTGO 0x0b
|
||||
#define POKEY_OFFSET_SEROUT 0x0d
|
||||
#define POKEY_OFFSET_IRQEN 0x0e
|
||||
#define POKEY_OFFSET_SKCTL 0x0f
|
||||
|
||||
#define POKEY_OFFSET_POT0 0x00
|
||||
#define POKEY_OFFSET_POT1 0x01
|
||||
#define POKEY_OFFSET_POT2 0x02
|
||||
#define POKEY_OFFSET_POT3 0x03
|
||||
#define POKEY_OFFSET_POT4 0x04
|
||||
#define POKEY_OFFSET_POT5 0x05
|
||||
#define POKEY_OFFSET_POT6 0x06
|
||||
#define POKEY_OFFSET_POT7 0x07
|
||||
#define POKEY_OFFSET_ALLPOT 0x08
|
||||
#define POKEY_OFFSET_KBCODE 0x09
|
||||
#define POKEY_OFFSET_RANDOM 0x0a
|
||||
#define POKEY_OFFSET_SERIN 0x0d
|
||||
#define POKEY_OFFSET_IRQST 0x0e
|
||||
#define POKEY_OFFSET_SKSTAT 0x0f
|
||||
|
||||
/* CONSTANT DEFINITIONS */
|
||||
|
||||
/* definitions for AUDCx (D201, D203, D205, D207) */
|
||||
#define POKEY_NOTPOLY5 0x80 /* selects POLY5 or direct CLOCK */
|
||||
#define POKEY_POLY4 0x40 /* selects POLY4 or POLY17 */
|
||||
#define POKEY_PURETONE 0x20 /* selects POLY4/17 or PURE tone */
|
||||
#define POKEY_VOL_ONLY 0x10 /* selects VOLUME OUTPUT ONLY */
|
||||
#define POKEY_VOLUME_MASK 0x0f /* volume mask */
|
||||
|
||||
/* definitions for AUDCTL (D208) */
|
||||
#define POKEY_POLY9 0x80 /* selects POLY9 or POLY17 */
|
||||
#define POKEY_CH1_179 0x40 /* selects 1.78979 MHz for Ch 1 */
|
||||
#define POKEY_CH3_179 0x20 /* selects 1.78979 MHz for Ch 3 */
|
||||
#define POKEY_CH1_CH2 0x10 /* clocks channel 1 w/channel 2 */
|
||||
#define POKEY_CH3_CH4 0x08 /* clocks channel 3 w/channel 4 */
|
||||
#define POKEY_CH1_FILTER 0x04 /* selects channel 1 high pass filter */
|
||||
#define POKEY_CH2_FILTER 0x02 /* selects channel 2 high pass filter */
|
||||
#define POKEY_CLOCK_15 0x01 /* selects 15.6999kHz or 63.9210kHz */
|
||||
|
||||
/* for accuracy, the 64kHz and 15kHz clocks are exact divisions of
|
||||
the 1.79MHz clock */
|
||||
#define POKEY_DIV_64 28 /* divisor for 1.79MHz clock to 64 kHz */
|
||||
#define POKEY_DIV_15 114 /* divisor for 1.79MHz clock to 15 kHz */
|
||||
|
||||
/* the size (in entries) of the 4 polynomial tables */
|
||||
#define POKEY_POLY4_SIZE 0x000f
|
||||
#define POKEY_POLY5_SIZE 0x001f
|
||||
#define POKEY_POLY9_SIZE 0x01ff
|
||||
#define POKEY_POLY17_SIZE 0x0001ffff
|
||||
|
||||
#define POKEY_MAXPOKEYS 2 /* max number of emulated chips */
|
||||
|
||||
/* channel/chip definitions */
|
||||
#define POKEY_CHAN1 0
|
||||
#define POKEY_CHAN2 1
|
||||
#define POKEY_CHAN3 2
|
||||
#define POKEY_CHAN4 3
|
||||
#define POKEY_CHIP1 0
|
||||
#define POKEY_CHIP2 4
|
||||
#define POKEY_CHIP3 8
|
||||
#define POKEY_CHIP4 12
|
||||
#define POKEY_SAMPLE 127
|
||||
|
||||
#endif /* POKEY_H_ */
|
||||
|
|
@ -306,9 +306,9 @@ void DivPlatformTX81Z::tick(bool sysTick) {
|
|||
chan[i].freq=chan[i].baseFreq+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
if (!parent->song.oldArpStrategy) {
|
||||
if (chan[i].fixedArp) {
|
||||
chan[i].freq=(chan[i].baseNoteOverride<<7)+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
chan[i].freq=(chan[i].baseNoteOverride<<6)+(chan[i].pitch>>1)-64+chan[i].pitch2;
|
||||
} else {
|
||||
chan[i].freq+=chan[i].arpOff<<7;
|
||||
chan[i].freq+=chan[i].arpOff<<6;
|
||||
}
|
||||
}
|
||||
if (chan[i].freq<0) chan[i].freq=0;
|
||||
|
|
|
|||
|
|
@ -41,15 +41,30 @@ int DivPlatformYM2203Ext::dispatch(DivCommand c) {
|
|||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
|
||||
if (opChan[ch].insChanged) {
|
||||
chan[2].state.alg=ins->fm.alg;
|
||||
chan[2].state.fb=ins->fm.fb;
|
||||
chan[2].state.op[ordch]=ins->fm.op[ordch];
|
||||
}
|
||||
|
||||
if (noExtMacros) {
|
||||
opChan[ch].macroInit(NULL);
|
||||
} else {
|
||||
opChan[ch].macroInit(ins);
|
||||
}
|
||||
if (!opChan[ch].std.vol.will) {
|
||||
opChan[ch].outVol=opChan[ch].vol;
|
||||
}
|
||||
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[ordch];
|
||||
// TODO: how does this work?!
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (opChan[ch].insChanged) {
|
||||
|
|
@ -62,13 +77,14 @@ int DivPlatformYM2203Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].mask=op.enable;
|
||||
}
|
||||
if (opChan[ch].insChanged) { // TODO how does this work?
|
||||
rWrite(chanOffs[2]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[2]+0xb0,(chan[2].state.alg&7)|(chan[2].state.fb<<3));
|
||||
}
|
||||
opChan[ch].insChanged=false;
|
||||
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
opChan[ch].baseFreq=NOTE_FNUM_BLOCK(c.value,11);
|
||||
opChan[ch].portaPause=false;
|
||||
opChan[ch].note=c.value;
|
||||
opChan[ch].freqChanged=true;
|
||||
}
|
||||
opChan[ch].keyOn=true;
|
||||
|
|
@ -80,15 +96,28 @@ int DivPlatformYM2203Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF_ENV:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].keyOff=true;
|
||||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_ENV_RELEASE:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_VOLUME: {
|
||||
opChan[ch].vol=c.value;
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (!opChan[ch].std.vol.has) {
|
||||
opChan[ch].outVol=c.value;
|
||||
}
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -144,29 +173,28 @@ int DivPlatformYM2203Ext::dispatch(DivCommand c) {
|
|||
immWrite(0x27,extMode?0x40:0);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
chan[2].state.fb=c.value&7;
|
||||
rWrite(chanOffs[2]+ADDR_FB_ALG,(chan[2].state.alg&7)|(chan[2].state.fb<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
case DIV_CMD_FM_MULT: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.mult=c.value2&15;
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
case DIV_CMD_FM_TL: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (isOutput[ins->fm.alg][c.value]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-c.value2)*(opChan[ch].vol&0x7f))/127));
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.tl=c.value2;
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,c.value)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,c.value2);
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -360,6 +388,92 @@ void DivPlatformYM2203Ext::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
if (extMode && !noExtMacros) for (int i=0; i<4; i++) {
|
||||
opChan[i].std.next();
|
||||
|
||||
if (opChan[i].std.vol.had) {
|
||||
opChan[i].outVol=VOL_SCALE_LOG_BROKEN(opChan[i].vol,MIN(127,opChan[i].std.vol.val),127);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[i]];
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
|
||||
if (opChan[i].std.arp.had) {
|
||||
if (!opChan[i].inPorta) {
|
||||
opChan[i].baseFreq=NOTE_FNUM_BLOCK(parent->calcArp(opChan[i].note,opChan[i].std.arp.val),11);
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
if (opChan[i].std.pitch.had) {
|
||||
if (opChan[i].std.pitch.mode) {
|
||||
opChan[i].pitch2+=opChan[i].std.pitch.val;
|
||||
CLAMP_VAR(opChan[i].pitch2,-32768,32767);
|
||||
} else {
|
||||
opChan[i].pitch2=opChan[i].std.pitch.val;
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
// param macros
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[i]];
|
||||
DivMacroInt::IntOp& m=opChan[i].std.op[orderedOps[i]];
|
||||
if (m.am.had) {
|
||||
op.am=m.am.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.ar.had) {
|
||||
op.ar=m.ar.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dr.had) {
|
||||
op.dr=m.dr.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.mult.had) {
|
||||
op.mult=m.mult.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.rr.had) {
|
||||
op.rr=m.rr.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.sl.had) {
|
||||
op.sl=m.sl.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.tl.had) {
|
||||
op.tl=127-m.tl.val;
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (m.rs.had) {
|
||||
op.rs=m.rs.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dt.had) {
|
||||
op.dt=m.dt.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.d2r.had) {
|
||||
op.d2r=m.d2r.val;
|
||||
rWrite(baseAddr+ADDR_DT2_D2R,op.d2r&31);
|
||||
}
|
||||
if (m.ssg.had) {
|
||||
op.ssgEnv=m.ssg.val;
|
||||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DivPlatformYM2203::tick(sysTick);
|
||||
|
||||
bool writeNoteOn=false;
|
||||
|
|
@ -411,15 +525,17 @@ void DivPlatformYM2203Ext::muteChannel(int ch, bool mute) {
|
|||
isOpMuted[ch-2]=mute;
|
||||
|
||||
int ordch=orderedOps[ch-2];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch-2].ins,DIV_INS_FM);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator op=chan[2].state.op[ordch];
|
||||
if (isOpMuted[ch-2]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (isOutput[ins->fm.alg][ordch]) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].vol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,ordch)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].outVol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
immWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -428,13 +544,23 @@ void DivPlatformYM2203Ext::forceIns() {
|
|||
for (int j=0; j<4; j++) {
|
||||
unsigned short baseAddr=chanOffs[i]|opOffs[j];
|
||||
DivInstrumentFM::Operator& op=chan[i].state.op[j];
|
||||
if (isMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
if (KVS(i,j)) {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,chan[i].outVol&0x7f,127));
|
||||
if (i==2 && extMode) { // extended channel
|
||||
if (isOpMuted[j]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(i,j)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,op.tl);
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
} else {
|
||||
if (isMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
if (KVS(i,j)) {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,chan[i].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,op.tl);
|
||||
}
|
||||
}
|
||||
}
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
|
|
@ -475,7 +601,7 @@ void* DivPlatformYM2203Ext::getChanState(int ch) {
|
|||
|
||||
DivMacroInt* DivPlatformYM2203Ext::getChanMacroInt(int ch) {
|
||||
if (ch>=6) return ay->getChanMacroInt(ch-6);
|
||||
if (ch>=2) return NULL; // currently not implemented
|
||||
if (ch>=2) return &opChan[ch-2].std;
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
|
|
@ -490,7 +616,9 @@ void DivPlatformYM2203Ext::reset() {
|
|||
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i]=DivPlatformOPN::OPNOpChannel();
|
||||
opChan[i].std.setEngine(parent);
|
||||
opChan[i].vol=127;
|
||||
opChan[i].outVol=127;
|
||||
}
|
||||
|
||||
// channel 2 mode
|
||||
|
|
|
|||
|
|
@ -950,7 +950,9 @@ int DivPlatformYM2608::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
if (c.chan>=6) break;
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -1200,6 +1202,7 @@ void DivPlatformYM2608::forceIns() {
|
|||
chan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=9; i<16; i++) {
|
||||
chan[i].insChanged=true;
|
||||
if (i>14) { // ADPCM-B
|
||||
|
|
@ -1276,6 +1279,7 @@ void DivPlatformYM2608::reset() {
|
|||
}
|
||||
|
||||
lastBusy=60;
|
||||
lfoValue=8;
|
||||
sampleBank=0;
|
||||
writeRSSOff=0;
|
||||
writeRSSOn=0;
|
||||
|
|
@ -1286,7 +1290,7 @@ void DivPlatformYM2608::reset() {
|
|||
extMode=false;
|
||||
|
||||
// LFO
|
||||
immWrite(0x22,0x08);
|
||||
immWrite(0x22,lfoValue);
|
||||
|
||||
// PCM volume
|
||||
immWrite(0x11,globalRSSVolume); // A
|
||||
|
|
|
|||
|
|
@ -41,15 +41,32 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
|
||||
if (opChan[ch].insChanged) {
|
||||
chan[2].state.alg=ins->fm.alg;
|
||||
chan[2].state.fb=ins->fm.fb;
|
||||
chan[2].state.fms=ins->fm.fms;
|
||||
chan[2].state.ams=ins->fm.ams;
|
||||
chan[2].state.op[ordch]=ins->fm.op[ordch];
|
||||
}
|
||||
|
||||
if (noExtMacros) {
|
||||
opChan[ch].macroInit(NULL);
|
||||
} else {
|
||||
opChan[ch].macroInit(ins);
|
||||
}
|
||||
if (!opChan[ch].std.vol.will) {
|
||||
opChan[ch].outVol=opChan[ch].vol;
|
||||
}
|
||||
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[ordch];
|
||||
// TODO: how does this work?!
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (opChan[ch].insChanged) {
|
||||
|
|
@ -62,14 +79,15 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].mask=op.enable;
|
||||
}
|
||||
if (opChan[ch].insChanged) { // TODO how does this work?
|
||||
rWrite(chanOffs[2]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[2]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[2]+0xb0,(chan[2].state.alg&7)|(chan[2].state.fb<<3));
|
||||
rWrite(chanOffs[2]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[2].state.fms&7)|((chan[2].state.ams&3)<<4));
|
||||
}
|
||||
opChan[ch].insChanged=false;
|
||||
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
opChan[ch].baseFreq=NOTE_FNUM_BLOCK(c.value,11);
|
||||
opChan[ch].portaPause=false;
|
||||
opChan[ch].note=c.value;
|
||||
opChan[ch].freqChanged=true;
|
||||
}
|
||||
opChan[ch].keyOn=true;
|
||||
|
|
@ -81,15 +99,28 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF_ENV:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].keyOff=true;
|
||||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_ENV_RELEASE:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_VOLUME: {
|
||||
opChan[ch].vol=c.value;
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (!opChan[ch].std.vol.has) {
|
||||
opChan[ch].outVol=c.value;
|
||||
}
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -109,14 +140,13 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
} else {
|
||||
opChan[ch].pan=(c.value2>0)|((c.value>0)<<1);
|
||||
}
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (parent->song.sharedExtStat) {
|
||||
for (int i=0; i<4; i++) {
|
||||
if (ch==i) continue;
|
||||
opChan[i].pan=opChan[ch].pan;
|
||||
}
|
||||
}
|
||||
rWrite(chanOffs[2]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[2]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[2].state.fms&7)|((chan[2].state.ams&3)<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_PITCH: {
|
||||
|
|
@ -162,7 +192,8 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -170,20 +201,23 @@ int DivPlatformYM2608Ext::dispatch(DivCommand c) {
|
|||
rWrite(chanOffs[2]+ADDR_FB_ALG,(chan[2].state.alg&7)|(chan[2].state.fb<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
case DIV_CMD_FM_MULT: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.mult=c.value2&15;
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
case DIV_CMD_FM_TL: {
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (isOutput[ins->fm.alg][c.value]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-c.value2)*(opChan[ch].vol&0x7f))/127));
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[c.value]];
|
||||
op.tl=c.value2;
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,c.value)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,c.value2);
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -377,6 +411,91 @@ void DivPlatformYM2608Ext::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
if (extMode && !noExtMacros) for (int i=0; i<4; i++) {
|
||||
opChan[i].std.next();
|
||||
|
||||
if (opChan[i].std.vol.had) {
|
||||
opChan[i].outVol=VOL_SCALE_LOG_BROKEN(opChan[i].vol,MIN(127,opChan[i].std.vol.val),127);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[i]];
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
|
||||
if (opChan[i].std.arp.had) {
|
||||
if (!opChan[i].inPorta) {
|
||||
opChan[i].baseFreq=NOTE_FNUM_BLOCK(parent->calcArp(opChan[i].note,opChan[i].std.arp.val),11);
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
if (opChan[i].std.pitch.had) {
|
||||
if (opChan[i].std.pitch.mode) {
|
||||
opChan[i].pitch2+=opChan[i].std.pitch.val;
|
||||
CLAMP_VAR(opChan[i].pitch2,-32768,32767);
|
||||
} else {
|
||||
opChan[i].pitch2=opChan[i].std.pitch.val;
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
// param macros
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[2].state.op[orderedOps[i]];
|
||||
DivMacroInt::IntOp& m=opChan[i].std.op[orderedOps[i]];
|
||||
if (m.am.had) {
|
||||
op.am=m.am.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.ar.had) {
|
||||
op.ar=m.ar.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dr.had) {
|
||||
op.dr=m.dr.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.mult.had) {
|
||||
op.mult=m.mult.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.rr.had) {
|
||||
op.rr=m.rr.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.sl.had) {
|
||||
op.sl=m.sl.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.tl.had) {
|
||||
op.tl=127-m.tl.val;
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (m.rs.had) {
|
||||
op.rs=m.rs.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dt.had) {
|
||||
op.dt=m.dt.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.d2r.had) {
|
||||
op.d2r=m.d2r.val;
|
||||
rWrite(baseAddr+ADDR_DT2_D2R,op.d2r&31);
|
||||
}
|
||||
if (m.ssg.had) {
|
||||
op.ssgEnv=m.ssg.val;
|
||||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
}
|
||||
|
||||
DivPlatformYM2608::tick(sysTick);
|
||||
|
||||
bool writeNoteOn=false;
|
||||
|
|
@ -428,16 +547,20 @@ void DivPlatformYM2608Ext::muteChannel(int ch, bool mute) {
|
|||
isOpMuted[ch-2]=mute;
|
||||
|
||||
int ordch=orderedOps[ch-2];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch-2].ins,DIV_INS_FM);
|
||||
unsigned short baseAddr=chanOffs[2]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator op=chan[2].state.op[ordch];
|
||||
if (isOpMuted[ch-2]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (isOutput[ins->fm.alg][ordch]) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].vol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,ordch)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].outVol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-2].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
immWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
||||
rWrite(chanOffs[2]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch-2].pan<<6))|(chan[2].state.fms&7)|((chan[2].state.ams&3)<<4));
|
||||
}
|
||||
|
||||
void DivPlatformYM2608Ext::forceIns() {
|
||||
|
|
@ -445,11 +568,11 @@ void DivPlatformYM2608Ext::forceIns() {
|
|||
for (int j=0; j<4; j++) {
|
||||
unsigned short baseAddr=chanOffs[i]|opOffs[j];
|
||||
DivInstrumentFM::Operator& op=chan[i].state.op[j];
|
||||
if (i==2) { // extended channel
|
||||
if (i==2 && extMode) { // extended channel
|
||||
if (isOpMuted[j]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(i,j)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
|
@ -472,7 +595,11 @@ void DivPlatformYM2608Ext::forceIns() {
|
|||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
rWrite(chanOffs[i]+ADDR_FB_ALG,(chan[i].state.alg&7)|(chan[i].state.fb<<3));
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
if (i==2) {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(IS_EXTCH_MUTED?0:(opChan[0].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
} else {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
}
|
||||
if (chan[i].active) {
|
||||
chan[i].keyOn=true;
|
||||
chan[i].freqChanged=true;
|
||||
|
|
@ -493,6 +620,7 @@ void DivPlatformYM2608Ext::forceIns() {
|
|||
immWrite(i.addr&15,i.val);
|
||||
}
|
||||
ay->getRegisterWrites().clear();
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i].insChanged=true;
|
||||
if (opChan[i].active) {
|
||||
|
|
@ -511,7 +639,7 @@ void* DivPlatformYM2608Ext::getChanState(int ch) {
|
|||
DivMacroInt* DivPlatformYM2608Ext::getChanMacroInt(int ch) {
|
||||
if (ch>=9 && ch<12) return ay->getChanMacroInt(ch-9);
|
||||
if (ch>=6) return &chan[ch-3].std;
|
||||
if (ch>=2) return NULL; // currently not implemented
|
||||
if (ch>=2) return &opChan[ch-2].std;
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
|
|
@ -526,7 +654,9 @@ void DivPlatformYM2608Ext::reset() {
|
|||
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i]=DivPlatformOPN::OPNOpChannelStereo();
|
||||
opChan[i].std.setEngine(parent);
|
||||
opChan[i].vol=127;
|
||||
opChan[i].outVol=127;
|
||||
}
|
||||
|
||||
// channel 2 mode
|
||||
|
|
|
|||
|
|
@ -930,7 +930,9 @@ int DivPlatformYM2610::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
if (c.chan>=psgChanOffs) break;
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -1173,6 +1175,7 @@ void DivPlatformYM2610::forceIns() {
|
|||
chan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=adpcmAChanOffs; i<=adpcmBChanOffs; i++) {
|
||||
chan[i].insChanged=true;
|
||||
}
|
||||
|
|
@ -1247,6 +1250,7 @@ void DivPlatformYM2610::reset() {
|
|||
}
|
||||
|
||||
lastBusy=60;
|
||||
lfoValue=8;
|
||||
sampleBank=0;
|
||||
DivPlatformYM2610Base::reset();
|
||||
|
||||
|
|
@ -1255,7 +1259,7 @@ void DivPlatformYM2610::reset() {
|
|||
extMode=false;
|
||||
|
||||
// LFO
|
||||
immWrite(0x22,0x08);
|
||||
immWrite(0x22,lfoValue);
|
||||
|
||||
// PCM volume
|
||||
immWrite(0x101,globalADPCMAVolume); // A
|
||||
|
|
|
|||
|
|
@ -993,7 +993,9 @@ int DivPlatformYM2610B::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
if (c.chan>=psgChanOffs) break;
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -1236,6 +1238,7 @@ void DivPlatformYM2610B::forceIns() {
|
|||
chan[i].freqChanged=true;
|
||||
}
|
||||
}
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=adpcmAChanOffs; i<=adpcmBChanOffs; i++) {
|
||||
chan[i].insChanged=true;
|
||||
}
|
||||
|
|
@ -1310,6 +1313,7 @@ void DivPlatformYM2610B::reset() {
|
|||
}
|
||||
|
||||
lastBusy=60;
|
||||
lfoValue=8;
|
||||
sampleBank=0;
|
||||
DivPlatformYM2610Base::reset();
|
||||
|
||||
|
|
@ -1318,7 +1322,7 @@ void DivPlatformYM2610B::reset() {
|
|||
extMode=false;
|
||||
|
||||
// LFO
|
||||
immWrite(0x22,0x08);
|
||||
immWrite(0x22,lfoValue);
|
||||
|
||||
// PCM volume
|
||||
immWrite(0x101,0x3f); // A
|
||||
|
|
|
|||
|
|
@ -37,15 +37,32 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
|
||||
if (opChan[ch].insChanged) {
|
||||
chan[extChanOffs].state.alg=ins->fm.alg;
|
||||
chan[extChanOffs].state.fb=ins->fm.fb;
|
||||
chan[extChanOffs].state.fms=ins->fm.fms;
|
||||
chan[extChanOffs].state.ams=ins->fm.ams;
|
||||
chan[extChanOffs].state.op[ordch]=ins->fm.op[ordch];
|
||||
}
|
||||
|
||||
if (noExtMacros) {
|
||||
opChan[ch].macroInit(NULL);
|
||||
} else {
|
||||
opChan[ch].macroInit(ins);
|
||||
}
|
||||
if (!opChan[ch].std.vol.will) {
|
||||
opChan[ch].outVol=opChan[ch].vol;
|
||||
}
|
||||
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[ordch];
|
||||
// TODO: how does this work?!
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (opChan[ch].insChanged) {
|
||||
|
|
@ -58,14 +75,15 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
opChan[ch].mask=op.enable;
|
||||
}
|
||||
if (opChan[ch].insChanged) { // TODO how does this work?
|
||||
rWrite(chanOffs[extChanOffs]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[extChanOffs]+0xb0,(chan[extChanOffs].state.alg&7)|(chan[extChanOffs].state.fb<<3));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
}
|
||||
opChan[ch].insChanged=false;
|
||||
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
opChan[ch].baseFreq=NOTE_FNUM_BLOCK(c.value,11);
|
||||
opChan[ch].portaPause=false;
|
||||
opChan[ch].note=c.value;
|
||||
opChan[ch].freqChanged=true;
|
||||
}
|
||||
opChan[ch].keyOn=true;
|
||||
|
|
@ -77,15 +95,28 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF_ENV:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].keyOff=true;
|
||||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_ENV_RELEASE:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_VOLUME: {
|
||||
opChan[ch].vol=c.value;
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (!opChan[ch].std.vol.has) {
|
||||
opChan[ch].outVol=c.value;
|
||||
}
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -105,14 +136,13 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
} else {
|
||||
opChan[ch].pan=(c.value2>0)|((c.value>0)<<1);
|
||||
}
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (parent->song.sharedExtStat) {
|
||||
for (int i=0; i<4; i++) {
|
||||
if (ch==i) continue;
|
||||
opChan[i].pan=opChan[ch].pan;
|
||||
}
|
||||
}
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_PITCH: {
|
||||
|
|
@ -158,7 +188,8 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -166,20 +197,23 @@ int DivPlatformYM2610BExt::dispatch(DivCommand c) {
|
|||
rWrite(chanOffs[extChanOffs]+ADDR_FB_ALG,(chan[extChanOffs].state.alg&7)|(chan[extChanOffs].state.fb<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
case DIV_CMD_FM_MULT: {
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[c.value]];
|
||||
op.mult=c.value2&15;
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
case DIV_CMD_FM_TL: {
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (isOutput[ins->fm.alg][c.value]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-c.value2)*(opChan[ch].vol&0x7f))/127));
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[c.value]];
|
||||
op.tl=c.value2;
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,c.value)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,c.value2);
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -373,6 +407,91 @@ void DivPlatformYM2610BExt::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
if (extMode && !noExtMacros) for (int i=0; i<4; i++) {
|
||||
opChan[i].std.next();
|
||||
|
||||
if (opChan[i].std.vol.had) {
|
||||
opChan[i].outVol=VOL_SCALE_LOG_BROKEN(opChan[i].vol,MIN(127,opChan[i].std.vol.val),127);
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[i]];
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
|
||||
if (opChan[i].std.arp.had) {
|
||||
if (!opChan[i].inPorta) {
|
||||
opChan[i].baseFreq=NOTE_FNUM_BLOCK(parent->calcArp(opChan[i].note,opChan[i].std.arp.val),11);
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
if (opChan[i].std.pitch.had) {
|
||||
if (opChan[i].std.pitch.mode) {
|
||||
opChan[i].pitch2+=opChan[i].std.pitch.val;
|
||||
CLAMP_VAR(opChan[i].pitch2,-32768,32767);
|
||||
} else {
|
||||
opChan[i].pitch2=opChan[i].std.pitch.val;
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
// param macros
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[i]];
|
||||
DivMacroInt::IntOp& m=opChan[i].std.op[orderedOps[i]];
|
||||
if (m.am.had) {
|
||||
op.am=m.am.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.ar.had) {
|
||||
op.ar=m.ar.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dr.had) {
|
||||
op.dr=m.dr.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.mult.had) {
|
||||
op.mult=m.mult.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.rr.had) {
|
||||
op.rr=m.rr.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.sl.had) {
|
||||
op.sl=m.sl.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.tl.had) {
|
||||
op.tl=127-m.tl.val;
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (m.rs.had) {
|
||||
op.rs=m.rs.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dt.had) {
|
||||
op.dt=m.dt.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.d2r.had) {
|
||||
op.d2r=m.d2r.val;
|
||||
rWrite(baseAddr+ADDR_DT2_D2R,op.d2r&31);
|
||||
}
|
||||
if (m.ssg.had) {
|
||||
op.ssgEnv=m.ssg.val;
|
||||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
}
|
||||
|
||||
DivPlatformYM2610B::tick(sysTick);
|
||||
|
||||
bool writeNoteOn=false;
|
||||
|
|
@ -424,16 +543,20 @@ void DivPlatformYM2610BExt::muteChannel(int ch, bool mute) {
|
|||
isOpMuted[ch-extChanOffs]=mute;
|
||||
|
||||
int ordch=orderedOps[ch-extChanOffs];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch-extChanOffs].ins,DIV_INS_FM);
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator op=chan[extChanOffs].state.op[ordch];
|
||||
if (isOpMuted[ch-extChanOffs]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (isOutput[ins->fm.alg][ordch]) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].vol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,ordch)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].outVol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
immWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch-extChanOffs].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
}
|
||||
|
||||
void DivPlatformYM2610BExt::forceIns() {
|
||||
|
|
@ -441,11 +564,11 @@ void DivPlatformYM2610BExt::forceIns() {
|
|||
for (int j=0; j<4; j++) {
|
||||
unsigned short baseAddr=chanOffs[i]|opOffs[j];
|
||||
DivInstrumentFM::Operator& op=chan[i].state.op[j];
|
||||
if (i==2 && extMode) { // extended channel
|
||||
if (i==extChanOffs && extMode) { // extended channel
|
||||
if (isOpMuted[j]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(i,j)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
|
@ -468,7 +591,11 @@ void DivPlatformYM2610BExt::forceIns() {
|
|||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
rWrite(chanOffs[i]+ADDR_FB_ALG,(chan[i].state.alg&7)|(chan[i].state.fb<<3));
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
if (i==extChanOffs) {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(IS_EXTCH_MUTED?0:(opChan[0].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
} else {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
}
|
||||
if (chan[i].active) {
|
||||
chan[i].keyOn=true;
|
||||
chan[i].freqChanged=true;
|
||||
|
|
@ -484,6 +611,7 @@ void DivPlatformYM2610BExt::forceIns() {
|
|||
immWrite(i.addr&15,i.val);
|
||||
}
|
||||
ay->getRegisterWrites().clear();
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i].insChanged=true;
|
||||
if (opChan[i].active) {
|
||||
|
|
@ -502,7 +630,7 @@ void* DivPlatformYM2610BExt::getChanState(int ch) {
|
|||
DivMacroInt* DivPlatformYM2610BExt::getChanMacroInt(int ch) {
|
||||
if (ch>=(psgChanOffs+3) && ch<(adpcmAChanOffs+3)) return ay->getChanMacroInt(ch-psgChanOffs-3);
|
||||
if (ch>=(extChanOffs+4)) return &chan[ch-3].std;
|
||||
if (ch>=extChanOffs) return NULL; // currently not implemented
|
||||
if (ch>=extChanOffs) return &opChan[ch-extChanOffs].std;
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
|
|
@ -517,7 +645,9 @@ void DivPlatformYM2610BExt::reset() {
|
|||
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i]=DivPlatformOPN::OPNOpChannelStereo();
|
||||
opChan[i].std.setEngine(parent);
|
||||
opChan[i].vol=127;
|
||||
opChan[i].outVol=127;
|
||||
}
|
||||
|
||||
// channel 2 mode
|
||||
|
|
|
|||
|
|
@ -37,15 +37,32 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
switch (c.cmd) {
|
||||
case DIV_CMD_NOTE_ON: {
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
|
||||
if (opChan[ch].insChanged) {
|
||||
chan[extChanOffs].state.alg=ins->fm.alg;
|
||||
chan[extChanOffs].state.fb=ins->fm.fb;
|
||||
chan[extChanOffs].state.fms=ins->fm.fms;
|
||||
chan[extChanOffs].state.ams=ins->fm.ams;
|
||||
chan[extChanOffs].state.op[ordch]=ins->fm.op[ordch];
|
||||
}
|
||||
|
||||
if (noExtMacros) {
|
||||
opChan[ch].macroInit(NULL);
|
||||
} else {
|
||||
opChan[ch].macroInit(ins);
|
||||
}
|
||||
if (!opChan[ch].std.vol.will) {
|
||||
opChan[ch].outVol=opChan[ch].vol;
|
||||
}
|
||||
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[ordch];
|
||||
// TODO: how does this work?!
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
if (opChan[ch].insChanged) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (opChan[ch].insChanged) {
|
||||
|
|
@ -58,14 +75,15 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].mask=op.enable;
|
||||
}
|
||||
if (opChan[ch].insChanged) { // TODO how does this work?
|
||||
rWrite(chanOffs[extChanOffs]+0xb0,(ins->fm.alg&7)|(ins->fm.fb<<3));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[extChanOffs]+0xb0,(chan[extChanOffs].state.alg&7)|(chan[extChanOffs].state.fb<<3));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
}
|
||||
opChan[ch].insChanged=false;
|
||||
|
||||
if (c.value!=DIV_NOTE_NULL) {
|
||||
opChan[ch].baseFreq=NOTE_FNUM_BLOCK(c.value,11);
|
||||
opChan[ch].portaPause=false;
|
||||
opChan[ch].note=c.value;
|
||||
opChan[ch].freqChanged=true;
|
||||
}
|
||||
opChan[ch].keyOn=true;
|
||||
|
|
@ -77,15 +95,28 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
break;
|
||||
case DIV_CMD_NOTE_OFF_ENV:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].keyOff=true;
|
||||
opChan[ch].keyOn=false;
|
||||
opChan[ch].active=false;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_ENV_RELEASE:
|
||||
if (noExtMacros) break;
|
||||
opChan[ch].std.release();
|
||||
break;
|
||||
case DIV_CMD_VOLUME: {
|
||||
opChan[ch].vol=c.value;
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (!opChan[ch].std.vol.has) {
|
||||
opChan[ch].outVol=c.value;
|
||||
}
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -105,14 +136,13 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
} else {
|
||||
opChan[ch].pan=(c.value2>0)|((c.value>0)<<1);
|
||||
}
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (parent->song.sharedExtStat) {
|
||||
for (int i=0; i<4; i++) {
|
||||
if (ch==i) continue;
|
||||
opChan[i].pan=opChan[ch].pan;
|
||||
}
|
||||
}
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(opChan[ch].pan<<6)|(ins->fm.fms&7)|((ins->fm.ams&3)<<4));
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_PITCH: {
|
||||
|
|
@ -158,7 +188,8 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_FM_LFO: {
|
||||
rWrite(0x22,(c.value&7)|((c.value>>4)<<3));
|
||||
lfoValue=(c.value&7)|((c.value>>4)<<3);
|
||||
rWrite(0x22,lfoValue);
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_FB: {
|
||||
|
|
@ -166,20 +197,23 @@ int DivPlatformYM2610Ext::dispatch(DivCommand c) {
|
|||
rWrite(chanOffs[extChanOffs]+ADDR_FB_ALG,(chan[extChanOffs].state.alg&7)|(chan[extChanOffs].state.fb<<3));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_MULT: { // TODO
|
||||
case DIV_CMD_FM_MULT: {
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
DivInstrumentFM::Operator op=ins->fm.op[orderedOps[c.value]];
|
||||
rWrite(baseAddr+0x30,(c.value2&15)|(dtTable[op.dt&7]<<4));
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[c.value]];
|
||||
op.mult=c.value2&15;
|
||||
rWrite(baseAddr+0x30,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_FM_TL: { // TODO
|
||||
case DIV_CMD_FM_TL: {
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[c.value]];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
if (isOutput[ins->fm.alg][c.value]) {
|
||||
rWrite(baseAddr+0x40,127-(((127-c.value2)*(opChan[ch].vol&0x7f))/127));
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[c.value]];
|
||||
op.tl=c.value2;
|
||||
if (isOpMuted[ch]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,c.value)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,c.value2);
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -373,6 +407,91 @@ void DivPlatformYM2610Ext::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
|
||||
if (extMode && !noExtMacros) for (int i=0; i<4; i++) {
|
||||
opChan[i].std.next();
|
||||
|
||||
if (opChan[i].std.vol.had) {
|
||||
opChan[i].outVol=VOL_SCALE_LOG_BROKEN(opChan[i].vol,MIN(127,opChan[i].std.vol.val),127);
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[i]];
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
|
||||
if (opChan[i].std.arp.had) {
|
||||
if (!opChan[i].inPorta) {
|
||||
opChan[i].baseFreq=NOTE_FNUM_BLOCK(parent->calcArp(opChan[i].note,opChan[i].std.arp.val),11);
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
if (opChan[i].std.pitch.had) {
|
||||
if (opChan[i].std.pitch.mode) {
|
||||
opChan[i].pitch2+=opChan[i].std.pitch.val;
|
||||
CLAMP_VAR(opChan[i].pitch2,-32768,32767);
|
||||
} else {
|
||||
opChan[i].pitch2=opChan[i].std.pitch.val;
|
||||
}
|
||||
opChan[i].freqChanged=true;
|
||||
}
|
||||
|
||||
// param macros
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[orderedOps[i]];
|
||||
DivInstrumentFM::Operator& op=chan[extChanOffs].state.op[orderedOps[i]];
|
||||
DivMacroInt::IntOp& m=opChan[i].std.op[orderedOps[i]];
|
||||
if (m.am.had) {
|
||||
op.am=m.am.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.ar.had) {
|
||||
op.ar=m.ar.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dr.had) {
|
||||
op.dr=m.dr.val;
|
||||
rWrite(baseAddr+ADDR_AM_DR,(op.dr&31)|(op.am<<7));
|
||||
}
|
||||
if (m.mult.had) {
|
||||
op.mult=m.mult.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.rr.had) {
|
||||
op.rr=m.rr.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.sl.had) {
|
||||
op.sl=m.sl.val;
|
||||
rWrite(baseAddr+ADDR_SL_RR,(op.rr&15)|(op.sl<<4));
|
||||
}
|
||||
if (m.tl.had) {
|
||||
op.tl=127-m.tl.val;
|
||||
if (isOpMuted[i]) {
|
||||
rWrite(baseAddr+ADDR_TL,127);
|
||||
} else {
|
||||
rWrite(baseAddr+ADDR_TL,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[i].outVol&0x7f,127));
|
||||
}
|
||||
}
|
||||
if (m.rs.had) {
|
||||
op.rs=m.rs.val;
|
||||
rWrite(baseAddr+ADDR_RS_AR,(op.ar&31)|(op.rs<<6));
|
||||
}
|
||||
if (m.dt.had) {
|
||||
op.dt=m.dt.val;
|
||||
rWrite(baseAddr+ADDR_MULT_DT,(op.mult&15)|(dtTable[op.dt&7]<<4));
|
||||
}
|
||||
if (m.d2r.had) {
|
||||
op.d2r=m.d2r.val;
|
||||
rWrite(baseAddr+ADDR_DT2_D2R,op.d2r&31);
|
||||
}
|
||||
if (m.ssg.had) {
|
||||
op.ssgEnv=m.ssg.val;
|
||||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
}
|
||||
|
||||
DivPlatformYM2610::tick(sysTick);
|
||||
|
||||
bool writeNoteOn=false;
|
||||
|
|
@ -424,16 +543,20 @@ void DivPlatformYM2610Ext::muteChannel(int ch, bool mute) {
|
|||
isOpMuted[ch-extChanOffs]=mute;
|
||||
|
||||
int ordch=orderedOps[ch-extChanOffs];
|
||||
DivInstrument* ins=parent->getIns(opChan[ch].ins,DIV_INS_FM);
|
||||
unsigned short baseAddr=chanOffs[extChanOffs]|opOffs[ordch];
|
||||
DivInstrumentFM::Operator op=ins->fm.op[ordch];
|
||||
if (isOpMuted[ch]) {
|
||||
DivInstrumentFM::Operator op=chan[extChanOffs].state.op[ordch];
|
||||
if (isOpMuted[ch-extChanOffs]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (isOutput[ins->fm.alg][ordch]) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].vol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(2,ordch)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].outVol&0x7f,127));
|
||||
immWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[ch-extChanOffs].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
immWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
||||
rWrite(chanOffs[extChanOffs]+0xb4,(IS_EXTCH_MUTED?0:(opChan[ch-extChanOffs].pan<<6))|(chan[extChanOffs].state.fms&7)|((chan[extChanOffs].state.ams&3)<<4));
|
||||
}
|
||||
|
||||
void DivPlatformYM2610Ext::forceIns() {
|
||||
|
|
@ -441,11 +564,11 @@ void DivPlatformYM2610Ext::forceIns() {
|
|||
for (int j=0; j<4; j++) {
|
||||
unsigned short baseAddr=chanOffs[i]|opOffs[j];
|
||||
DivInstrumentFM::Operator& op=chan[i].state.op[j];
|
||||
if (i==1 && extMode) { // extended channel
|
||||
if (i==extChanOffs && extMode) { // extended channel
|
||||
if (isOpMuted[j]) {
|
||||
rWrite(baseAddr+0x40,127);
|
||||
} else if (KVS(i,j)) {
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].vol&0x7f,127));
|
||||
rWrite(baseAddr+0x40,127-VOL_SCALE_LOG_BROKEN(127-op.tl,opChan[j].outVol&0x7f,127));
|
||||
} else {
|
||||
rWrite(baseAddr+0x40,op.tl);
|
||||
}
|
||||
|
|
@ -468,7 +591,11 @@ void DivPlatformYM2610Ext::forceIns() {
|
|||
rWrite(baseAddr+ADDR_SSG,op.ssgEnv&15);
|
||||
}
|
||||
rWrite(chanOffs[i]+ADDR_FB_ALG,(chan[i].state.alg&7)|(chan[i].state.fb<<3));
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
if (i==extChanOffs) {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(IS_EXTCH_MUTED?0:(opChan[0].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
} else {
|
||||
rWrite(chanOffs[i]+ADDR_LRAF,(isMuted[i]?0:(chan[i].pan<<6))|(chan[i].state.fms&7)|((chan[i].state.ams&3)<<4));
|
||||
}
|
||||
if (chan[i].active) {
|
||||
chan[i].keyOn=true;
|
||||
chan[i].freqChanged=true;
|
||||
|
|
@ -484,6 +611,7 @@ void DivPlatformYM2610Ext::forceIns() {
|
|||
immWrite(i.addr&15,i.val);
|
||||
}
|
||||
ay->getRegisterWrites().clear();
|
||||
immWrite(0x22,lfoValue);
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i].insChanged=true;
|
||||
if (opChan[i].active) {
|
||||
|
|
@ -502,7 +630,7 @@ void* DivPlatformYM2610Ext::getChanState(int ch) {
|
|||
DivMacroInt* DivPlatformYM2610Ext::getChanMacroInt(int ch) {
|
||||
if (ch>=(psgChanOffs+3) && ch<(adpcmAChanOffs+3)) return ay->getChanMacroInt(ch-psgChanOffs-3);
|
||||
if (ch>=(extChanOffs+4)) return &chan[ch-3].std;
|
||||
if (ch>=extChanOffs) return NULL; // currently not implemented
|
||||
if (ch>=extChanOffs) return &opChan[ch-extChanOffs].std;
|
||||
return &chan[ch].std;
|
||||
}
|
||||
|
||||
|
|
@ -517,7 +645,9 @@ void DivPlatformYM2610Ext::reset() {
|
|||
|
||||
for (int i=0; i<4; i++) {
|
||||
opChan[i]=DivPlatformOPN::OPNOpChannelStereo();
|
||||
opChan[i].std.setEngine(parent);
|
||||
opChan[i].vol=127;
|
||||
opChan[i].outVol=127;
|
||||
}
|
||||
|
||||
// channel 2 mode
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue