2022-03-06 16:13:47 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2023-01-20 00:18:40 +00:00
|
|
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
2022-03-06 16:13:47 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
#include "swan.h"
|
2022-03-06 16:13:47 +00:00
|
|
|
#include "../engine.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);}}
|
2023-01-15 06:46:34 +00:00
|
|
|
#define postWrite(a,v) postDACWrites.emplace(a,v);
|
2022-03-06 16:13:47 +00:00
|
|
|
|
|
|
|
#define CHIP_DIVIDER 32
|
|
|
|
|
|
|
|
const char* regCheatSheetWS[]={
|
|
|
|
"CH1_Pitch", "00",
|
|
|
|
"CH2_Pitch", "02",
|
|
|
|
"CH3_Pitch", "04",
|
|
|
|
"CH4_Pitch", "06",
|
|
|
|
"CH1_Vol", "08",
|
|
|
|
"CH2_Vol", "09",
|
|
|
|
"CH3_Vol", "0A",
|
|
|
|
"CH4_Vol", "0B",
|
|
|
|
"Sweep_Value", "0C",
|
|
|
|
"Sweep_Time", "0D",
|
|
|
|
"Noise", "0E",
|
|
|
|
"Wave_Base", "0F",
|
|
|
|
"Ctrl", "10",
|
|
|
|
"Output", "11",
|
|
|
|
"Random", "12",
|
|
|
|
"Voice_Ctrl", "14",
|
|
|
|
"Wave_Mem", "40",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
const char** DivPlatformSwan::getRegisterSheet() {
|
2022-03-06 16:13:47 +00:00
|
|
|
return regCheatSheetWS;
|
|
|
|
}
|
|
|
|
|
2023-01-02 09:53:37 +00:00
|
|
|
void DivPlatformSwan::acquire(short** buf, size_t len) {
|
2023-01-03 06:09:46 +00:00
|
|
|
for (size_t h=0; h<len; h++) {
|
2022-03-06 16:13:47 +00:00
|
|
|
// PCM part
|
|
|
|
if (pcm && dacSample!=-1) {
|
|
|
|
dacPeriod+=dacRate;
|
|
|
|
while (dacPeriod>rate) {
|
|
|
|
DivSample* s=parent->getSample(dacSample);
|
2022-08-28 00:59:56 +00:00
|
|
|
if (s->samples<=0) {
|
2022-03-06 16:13:47 +00:00
|
|
|
dacSample=-1;
|
2022-08-31 05:51:08 +00:00
|
|
|
dacPeriod=0;
|
|
|
|
break;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
rWrite(0x09,(unsigned char)s->data8[dacPos++]+0x80);
|
2022-08-28 01:50:57 +00:00
|
|
|
if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) {
|
|
|
|
dacPos=s->loopStart;
|
|
|
|
} else if (dacPos>=s->samples) {
|
2022-07-22 04:36:42 +00:00
|
|
|
dacSample=-1;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
dacPeriod-=rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// the rest
|
|
|
|
while (!writes.empty()) {
|
|
|
|
QueuedWrite w=writes.front();
|
2022-03-07 12:08:18 +00:00
|
|
|
regPool[w.addr]=w.val;
|
2022-03-07 08:44:15 +00:00
|
|
|
if (w.addr<0x40) ws->SoundWrite(w.addr|0x80,w.val);
|
|
|
|
else ws->RAMWrite(w.addr&0x3f,w.val);
|
2022-03-06 16:13:47 +00:00
|
|
|
writes.pop();
|
|
|
|
}
|
|
|
|
int16_t samp[2]{0, 0};
|
|
|
|
ws->SoundUpdate(16);
|
|
|
|
ws->SoundFlush(samp, 1);
|
2023-01-02 09:53:37 +00:00
|
|
|
buf[0][h]=samp[0];
|
|
|
|
buf[1][h]=samp[1];
|
per-channel oscilloscope, part 5
SAA1099 (SAASound and MAME), Lynx, MMC5, N163, PC Engine, PC Speaker,
PET, QSound, WonderSwan, VERA, VIC-20, VRC6 and X1-010!
2022-05-01 07:40:03 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
oscBuf[i]->data[oscBuf[i]->needle++]=(ws->sample_cache[i][0]+ws->sample_cache[i][1])<<6;
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::updateWave(int ch) {
|
2022-03-06 16:13:47 +00:00
|
|
|
unsigned char addr=0x40+ch*16;
|
2022-04-08 09:34:39 +00:00
|
|
|
for (int i=0; i<16; i++) {
|
|
|
|
int nibble1=chan[ch].ws.output[i<<1];
|
|
|
|
int nibble2=chan[ch].ws.output[1+(i<<1)];
|
|
|
|
rWrite(addr+i,nibble1|(nibble2<<4));
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::calcAndWriteOutVol(int ch, int env) {
|
2022-03-06 16:13:47 +00:00
|
|
|
int vl=chan[ch].vol*((chan[ch].pan>>4)&0x0f)*env/225;
|
|
|
|
int vr=chan[ch].vol*(chan[ch].pan&0x0f)*env/225;
|
|
|
|
if (ch==1&&pcm) {
|
|
|
|
vl=(vl>0)?((vl>7)?3:2):0;
|
|
|
|
vr=(vr>0)?((vr>7)?3:2):0;
|
|
|
|
chan[1].outVol=vr|(vl<<2);
|
|
|
|
} else {
|
|
|
|
chan[ch].outVol=vr|(vl<<4);
|
|
|
|
}
|
|
|
|
writeOutVol(ch);
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::writeOutVol(int ch) {
|
2022-03-06 16:13:47 +00:00
|
|
|
unsigned char val=isMuted[ch]?0:chan[ch].outVol;
|
|
|
|
if (ch==1&&pcm) {
|
|
|
|
rWrite(0x14,val)
|
|
|
|
} else {
|
|
|
|
rWrite(0x08+ch,val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 20:01:11 +00:00
|
|
|
void DivPlatformSwan::tick(bool sysTick) {
|
2022-03-06 16:13:47 +00:00
|
|
|
unsigned char sndCtrl=(pcm?0x20:0)|(sweep?0x40:0)|((noise>0)?0x80:0);
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
chan[i].std.next();
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.vol.had) {
|
|
|
|
int env=chan[i].std.vol.val;
|
2022-04-21 07:24:06 +00:00
|
|
|
if(parent->getIns(chan[i].ins,DIV_INS_SWAN)->type==DIV_INS_AMIGA) {
|
2022-03-06 16:13:47 +00:00
|
|
|
env=MIN(env/4,15);
|
|
|
|
}
|
|
|
|
calcAndWriteOutVol(i,env);
|
|
|
|
}
|
2022-12-17 06:21:08 +00:00
|
|
|
if (NEW_ARP_STRAT) {
|
|
|
|
chan[i].handleArp();
|
|
|
|
} else if (chan[i].std.arp.had) {
|
2022-03-06 16:13:47 +00:00
|
|
|
if (!chan[i].inPorta) {
|
2022-08-22 20:59:45 +00:00
|
|
|
chan[i].baseFreq=NOTE_PERIODIC(parent->calcArp(chan[i].note,chan[i].std.arp.val));
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.wave.had && !(i==1 && pcm)) {
|
|
|
|
if (chan[i].wave!=chan[i].std.wave.val || chan[i].ws.activeChanged()) {
|
|
|
|
chan[i].wave=chan[i].std.wave.val;
|
2022-04-08 09:34:39 +00:00
|
|
|
chan[i].ws.changeWave1(chan[i].wave);
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
2022-04-17 19:15:57 +00:00
|
|
|
if (chan[i].std.panL.had) {
|
|
|
|
chan[i].pan&=0x0f;
|
|
|
|
chan[i].pan|=(chan[i].std.panL.val&15)<<4;
|
|
|
|
}
|
|
|
|
if (chan[i].std.panR.had) {
|
|
|
|
chan[i].pan&=0xf0;
|
|
|
|
chan[i].pan|=chan[i].std.panR.val&15;
|
|
|
|
}
|
|
|
|
if (chan[i].std.panL.had || chan[i].std.panR.had) {
|
|
|
|
calcAndWriteOutVol(i,chan[i].std.vol.will?chan[i].std.vol.val:15);
|
|
|
|
}
|
2022-04-16 06:39:40 +00:00
|
|
|
if (chan[i].std.pitch.had) {
|
2022-04-28 06:31:16 +00:00
|
|
|
if (chan[i].std.pitch.mode) {
|
|
|
|
chan[i].pitch2+=chan[i].std.pitch.val;
|
2022-05-23 03:47:40 +00:00
|
|
|
CLAMP_VAR(chan[i].pitch2,-32768,32767);
|
2022-04-28 06:31:16 +00:00
|
|
|
} else {
|
|
|
|
chan[i].pitch2=chan[i].std.pitch.val;
|
|
|
|
}
|
2022-04-16 06:39:40 +00:00
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
if (chan[i].active) {
|
|
|
|
sndCtrl|=(1<<i);
|
2022-04-08 09:34:39 +00:00
|
|
|
if (chan[i].ws.tick()) {
|
|
|
|
updateWave(i);
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
2022-12-17 07:07:24 +00:00
|
|
|
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);
|
2022-03-06 18:26:59 +00:00
|
|
|
if (i==1 && pcm && furnaceDac) {
|
2022-03-06 16:13:47 +00:00
|
|
|
double off=1.0;
|
|
|
|
if (dacSample>=0 && dacSample<parent->song.sampleLen) {
|
|
|
|
DivSample* s=parent->getSample(dacSample);
|
|
|
|
if (s->centerRate<1) {
|
|
|
|
off=1.0;
|
|
|
|
} else {
|
|
|
|
off=8363.0/(double)s->centerRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dacRate=((double)chipClock/2)/MAX(1,off*chan[i].freq);
|
2023-01-15 06:46:34 +00:00
|
|
|
if (dumpWrites) postWrite(0xffff0001,dacRate);
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
if (chan[i].freq>2048) chan[i].freq=2048;
|
|
|
|
if (chan[i].freq<1) chan[i].freq=1;
|
|
|
|
int rVal=2048-chan[i].freq;
|
|
|
|
rWrite(i*2,rVal&0xff);
|
|
|
|
rWrite(i*2+1,rVal>>8);
|
|
|
|
if (chan[i].keyOn) {
|
2022-04-10 05:01:55 +00:00
|
|
|
if (!chan[i].std.vol.will) {
|
2022-03-06 16:13:47 +00:00
|
|
|
calcAndWriteOutVol(i,15);
|
|
|
|
}
|
|
|
|
chan[i].keyOn=false;
|
|
|
|
}
|
|
|
|
if (chan[i].keyOff) {
|
|
|
|
chan[i].keyOff=false;
|
|
|
|
}
|
|
|
|
chan[i].freqChanged=false;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[3].std.duty.had) {
|
2022-04-25 23:07:49 +00:00
|
|
|
if (noise!=chan[3].std.duty.val) {
|
|
|
|
noise=chan[3].std.duty.val;
|
|
|
|
if (noise>0) {
|
|
|
|
rWrite(0x0e,((noise-1)&0x07)|0x18);
|
|
|
|
sndCtrl|=0x80;
|
|
|
|
} else {
|
|
|
|
sndCtrl&=~0x80;
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-01-19 08:57:29 +00:00
|
|
|
if (chan[3].std.phaseReset.had) {
|
|
|
|
if (noise>0) {
|
|
|
|
rWrite(0x0e,((noise-1)&0x07)|0x18);
|
|
|
|
sndCtrl|=0x80;
|
|
|
|
} else {
|
|
|
|
sndCtrl&=~0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned char origSndCtrl=sndCtrl;
|
|
|
|
bool phaseResetHappens=false;
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
if (chan[i].std.phaseReset.had) {
|
|
|
|
phaseResetHappens=true;
|
|
|
|
sndCtrl&=~(1<<i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (phaseResetHappens) {
|
|
|
|
rWrite(0x10,sndCtrl);
|
|
|
|
sndCtrl=origSndCtrl;
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
rWrite(0x10,sndCtrl);
|
2023-01-15 06:46:34 +00:00
|
|
|
|
|
|
|
while (!postDACWrites.empty()) {
|
|
|
|
const DivRegWrite& w=postDACWrites.back();
|
|
|
|
if (dumpWrites) addWrite(w.addr,w.val);
|
|
|
|
postDACWrites.pop();
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
int DivPlatformSwan::dispatch(DivCommand c) {
|
2022-03-06 16:13:47 +00:00
|
|
|
switch (c.cmd) {
|
|
|
|
case DIV_CMD_NOTE_ON: {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_SWAN);
|
2022-03-06 18:26:59 +00:00
|
|
|
if (c.chan==1) {
|
Prepare for split sample chip instrument
(MSM6258, MSM6295, QSound, Sega PCM, ADPCM-A, ADPCM-B, YMZ280B, RF5C68)
Instrument color and icons are placeholder.
different volume range, hard panned/soft panned and/or independent volume per output, chip-dependent features (global volume, echo, etc)
Allow use sample in instrument tab for chip with sample support
Prepare to support X1-010 Seta 2 style bankswitch behavior
Prepare to support AY89x0 PCM DAC
Support volume for PCE sample (DAC)
Fix Lynx, Y8950 sample pitch matches to sample preview
Support PCM DAC with backward and pingpong loop mode
Reduce some codes
Add Sega PCM, AY89x0, QSound, PCM DAC, Lynx per-channel debug support
2022-08-27 07:27:36 +00:00
|
|
|
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) {
|
2022-03-06 18:26:59 +00:00
|
|
|
pcm=true;
|
|
|
|
} else if (furnaceDac) {
|
|
|
|
pcm=false;
|
|
|
|
}
|
|
|
|
if (pcm) {
|
|
|
|
if (skipRegisterWrites) break;
|
|
|
|
dacPos=0;
|
|
|
|
dacPeriod=0;
|
Prepare for split sample chip instrument
(MSM6258, MSM6295, QSound, Sega PCM, ADPCM-A, ADPCM-B, YMZ280B, RF5C68)
Instrument color and icons are placeholder.
different volume range, hard panned/soft panned and/or independent volume per output, chip-dependent features (global volume, echo, etc)
Allow use sample in instrument tab for chip with sample support
Prepare to support X1-010 Seta 2 style bankswitch behavior
Prepare to support AY89x0 PCM DAC
Support volume for PCE sample (DAC)
Fix Lynx, Y8950 sample pitch matches to sample preview
Support PCM DAC with backward and pingpong loop mode
Reduce some codes
Add Sega PCM, AY89x0, QSound, PCM DAC, Lynx per-channel debug support
2022-08-27 07:27:36 +00:00
|
|
|
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) {
|
2022-12-29 08:12:00 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) dacSample=ins->amiga.getSample(c.value);
|
2022-03-06 18:26:59 +00:00
|
|
|
if (dacSample<0 || dacSample>=parent->song.sampleLen) {
|
|
|
|
dacSample=-1;
|
2023-01-15 06:46:34 +00:00
|
|
|
if (dumpWrites) postWrite(0xffff0002,0);
|
2022-03-06 18:26:59 +00:00
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
if (dumpWrites) {
|
2023-01-15 06:46:34 +00:00
|
|
|
postWrite(0xffff0000,dacSample);
|
2022-03-06 18:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
|
|
|
chan[1].baseFreq=NOTE_PERIODIC(c.value);
|
|
|
|
chan[1].freqChanged=true;
|
|
|
|
chan[1].note=c.value;
|
|
|
|
}
|
|
|
|
chan[1].active=true;
|
|
|
|
chan[1].keyOn=true;
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[1].macroInit(ins);
|
2022-03-06 18:26:59 +00:00
|
|
|
furnaceDac=true;
|
2022-03-06 16:13:47 +00:00
|
|
|
} else {
|
2022-03-06 18:26:59 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
|
|
|
chan[1].note=c.value;
|
|
|
|
}
|
|
|
|
dacSample=12*sampleBank+chan[1].note%12;
|
|
|
|
if (dacSample>=parent->song.sampleLen) {
|
|
|
|
dacSample=-1;
|
2023-01-15 06:46:34 +00:00
|
|
|
if (dumpWrites) postWrite(0xffff0002,0);
|
2022-03-06 18:26:59 +00:00
|
|
|
break;
|
|
|
|
} else {
|
2023-01-15 06:46:34 +00:00
|
|
|
if (dumpWrites) postWrite(0xffff0000,dacSample);
|
2022-03-06 18:26:59 +00:00
|
|
|
}
|
|
|
|
dacRate=parent->getSample(dacSample)->rate;
|
2022-03-06 16:13:47 +00:00
|
|
|
if (dumpWrites) {
|
2023-01-15 06:46:34 +00:00
|
|
|
postWrite(0xffff0001,dacRate);
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
2022-03-06 18:26:59 +00:00
|
|
|
chan[1].active=true;
|
|
|
|
chan[1].keyOn=true;
|
|
|
|
furnaceDac=false;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
2022-03-06 18:26:59 +00:00
|
|
|
break;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[c.chan].macroInit(ins);
|
2022-06-01 00:03:31 +00:00
|
|
|
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) {
|
|
|
|
chan[c.chan].outVol=chan[c.chan].vol;
|
|
|
|
}
|
2022-04-08 09:34:39 +00:00
|
|
|
if (chan[c.chan].wave<0) {
|
|
|
|
chan[c.chan].wave=0;
|
|
|
|
chan[c.chan].ws.changeWave1(chan[c.chan].wave);
|
|
|
|
}
|
|
|
|
chan[c.chan].ws.init(ins,32,15,chan[c.chan].insChanged);
|
|
|
|
chan[c.chan].insChanged=false;
|
2022-03-06 16:13:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
if (c.chan==1&&pcm) {
|
|
|
|
dacSample=-1;
|
2023-01-15 06:46:34 +00:00
|
|
|
if (dumpWrites) postWrite(0xffff0002,0);
|
2022-03-06 16:13:47 +00:00
|
|
|
pcm=false;
|
|
|
|
}
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].keyOff=true;
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[c.chan].macroInit(NULL);
|
2022-03-06 16:13:47 +00:00
|
|
|
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;
|
2022-04-08 09:34:39 +00:00
|
|
|
chan[c.chan].insChanged=true;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_VOLUME:
|
|
|
|
if (chan[c.chan].vol!=c.value) {
|
|
|
|
chan[c.chan].vol=c.value;
|
2022-06-16 20:06:07 +00:00
|
|
|
if (!chan[c.chan].std.vol.has) {
|
2022-03-06 16:13:47 +00:00
|
|
|
calcAndWriteOutVol(c.chan,15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_GET_VOLUME:
|
|
|
|
return chan[c.chan].vol;
|
|
|
|
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;
|
2022-04-08 09:34:39 +00:00
|
|
|
chan[c.chan].ws.changeWave1(chan[c.chan].wave);
|
2022-03-06 16:13:47 +00:00
|
|
|
chan[c.chan].keyOn=true;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_WS_SWEEP_TIME:
|
|
|
|
if (c.chan==2) {
|
|
|
|
if (c.value==0) {
|
|
|
|
sweep=false;
|
|
|
|
} else {
|
|
|
|
sweep=true;
|
|
|
|
rWrite(0x0d,(c.value-1)&0xff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_WS_SWEEP_AMOUNT:
|
|
|
|
if (c.chan==2) {
|
|
|
|
rWrite(0x0c,c.value&0xff);
|
|
|
|
}
|
|
|
|
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_STD_NOISE_MODE:
|
|
|
|
if (c.chan==3) {
|
|
|
|
noise=c.value&0xff;
|
2022-03-08 04:09:42 +00:00
|
|
|
if (noise>0) rWrite(0x0e,((noise-1)&0x07)|0x18);
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_SAMPLE_MODE:
|
|
|
|
if (c.chan==1) pcm=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_SAMPLE_BANK:
|
|
|
|
sampleBank=c.value;
|
|
|
|
if (sampleBank>(parent->song.sample.size()/12)) {
|
|
|
|
sampleBank=parent->song.sample.size()/12;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PANNING: {
|
2022-04-30 04:41:14 +00:00
|
|
|
chan[c.chan].pan=(c.value&0xf0)|(c.value2>>4);
|
2022-04-10 05:01:55 +00:00
|
|
|
calcAndWriteOutVol(c.chan,chan[c.chan].std.vol.will?chan[c.chan].std.vol.val:15);
|
2022-03-06 16:13:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_LEGATO:
|
2022-12-17 07:07:24 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0)));
|
2022-03-06 16:13:47 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PRE_PORTA:
|
|
|
|
if (chan[c.chan].active && c.value2) {
|
2022-04-28 06:31:16 +00:00
|
|
|
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_SWAN));
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
2022-12-17 07:10:20 +00:00
|
|
|
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);
|
2022-03-06 16:13:47 +00:00
|
|
|
chan[c.chan].inPorta=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 15;
|
|
|
|
break;
|
2022-12-17 05:09:56 +00:00
|
|
|
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;
|
2022-03-06 16:13:47 +00:00
|
|
|
case DIV_ALWAYS_SET_VOLUME:
|
2022-03-06 18:26:59 +00:00
|
|
|
return 1;
|
2022-03-06 16:13:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::muteChannel(int ch, bool mute) {
|
2022-03-06 16:13:47 +00:00
|
|
|
isMuted[ch]=mute;
|
|
|
|
writeOutVol(ch);
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::forceIns() {
|
2022-05-14 02:44:34 +00:00
|
|
|
noise=0;
|
2022-03-06 16:13:47 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
updateWave(i);
|
|
|
|
writeOutVol(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void* DivPlatformSwan::getChanState(int ch) {
|
2022-03-06 16:13:47 +00:00
|
|
|
return &chan[ch];
|
|
|
|
}
|
|
|
|
|
2022-06-05 23:17:00 +00:00
|
|
|
DivMacroInt* DivPlatformSwan::getChanMacroInt(int ch) {
|
|
|
|
return &chan[ch].std;
|
|
|
|
}
|
|
|
|
|
per-channel oscilloscope, part 5
SAA1099 (SAASound and MAME), Lynx, MMC5, N163, PC Engine, PC Speaker,
PET, QSound, WonderSwan, VERA, VIC-20, VRC6 and X1-010!
2022-05-01 07:40:03 +00:00
|
|
|
DivDispatchOscBuffer* DivPlatformSwan::getOscBuffer(int ch) {
|
|
|
|
return oscBuf[ch];
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
unsigned char* DivPlatformSwan::getRegisterPool() {
|
2022-03-06 16:13:47 +00:00
|
|
|
// get Random from emulator
|
|
|
|
regPool[0x12]=ws->SoundRead(0x92);
|
|
|
|
regPool[0x13]=ws->SoundRead(0x93);
|
|
|
|
return regPool;
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
int DivPlatformSwan::getRegisterPoolSize() {
|
2022-03-06 16:13:47 +00:00
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::reset() {
|
2022-03-06 16:13:47 +00:00
|
|
|
while (!writes.empty()) writes.pop();
|
2023-01-15 06:46:34 +00:00
|
|
|
while (!postDACWrites.empty()) postDACWrites.pop();
|
2022-03-06 16:13:47 +00:00
|
|
|
memset(regPool,0,128);
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
chan[i]=Channel();
|
|
|
|
chan[i].vol=15;
|
|
|
|
chan[i].pan=0xff;
|
2022-04-15 10:37:23 +00:00
|
|
|
chan[i].std.setEngine(parent);
|
2022-04-08 09:34:39 +00:00
|
|
|
chan[i].ws.setEngine(parent);
|
|
|
|
chan[i].ws.init(NULL,32,15,false);
|
2022-03-06 18:26:59 +00:00
|
|
|
rWrite(0x08+i,0xff);
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
if (dumpWrites) {
|
|
|
|
addWrite(0xffffffff,0);
|
|
|
|
}
|
|
|
|
ws->SoundReset();
|
|
|
|
pcm=false;
|
|
|
|
sweep=false;
|
|
|
|
furnaceDac=false;
|
|
|
|
noise=0;
|
|
|
|
dacPeriod=0;
|
|
|
|
dacRate=0;
|
|
|
|
dacPos=0;
|
|
|
|
dacSample=-1;
|
|
|
|
sampleBank=0;
|
|
|
|
rWrite(0x0f,0x00); // wave table at 0x0000
|
|
|
|
rWrite(0x11,0x09); // enable speakers
|
|
|
|
}
|
|
|
|
|
2023-01-02 00:46:08 +00:00
|
|
|
int DivPlatformSwan::getOutputCount() {
|
|
|
|
return 2;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::notifyWaveChange(int wave) {
|
2022-03-06 16:13:47 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
if (chan[i].wave==wave) {
|
2022-04-08 09:34:39 +00:00
|
|
|
chan[i].ws.changeWave1(wave);
|
2022-03-06 16:13:47 +00:00
|
|
|
updateWave(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::notifyInsDeletion(void* ins) {
|
2022-03-06 16:13:47 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::poke(unsigned int addr, unsigned short val) {
|
2022-03-06 16:13:47 +00:00
|
|
|
rWrite(addr,val);
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::poke(std::vector<DivRegWrite>& wlist) {
|
2022-03-06 16:13:47 +00:00
|
|
|
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
|
|
|
}
|
|
|
|
|
2022-09-30 01:13:40 +00:00
|
|
|
int DivPlatformSwan::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
2022-03-06 16:13:47 +00:00
|
|
|
parent=p;
|
|
|
|
dumpWrites=false;
|
|
|
|
skipRegisterWrites=false;
|
|
|
|
chipClock=3072000;
|
2022-12-04 07:04:42 +00:00
|
|
|
CHECK_CUSTOM_CLOCK;
|
2022-03-06 16:13:47 +00:00
|
|
|
rate=chipClock/16; // = 192000kHz, should be enough
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
isMuted[i]=false;
|
per-channel oscilloscope, part 5
SAA1099 (SAASound and MAME), Lynx, MMC5, N163, PC Engine, PC Speaker,
PET, QSound, WonderSwan, VERA, VIC-20, VRC6 and X1-010!
2022-05-01 07:40:03 +00:00
|
|
|
oscBuf[i]=new DivDispatchOscBuffer;
|
|
|
|
oscBuf[i]->rate=rate;
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|
|
|
|
ws=new WSwan();
|
|
|
|
reset();
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
void DivPlatformSwan::quit() {
|
per-channel oscilloscope, part 5
SAA1099 (SAASound and MAME), Lynx, MMC5, N163, PC Engine, PC Speaker,
PET, QSound, WonderSwan, VERA, VIC-20, VRC6 and X1-010!
2022-05-01 07:40:03 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
delete oscBuf[i];
|
|
|
|
}
|
2022-03-06 16:13:47 +00:00
|
|
|
delete ws;
|
|
|
|
}
|
|
|
|
|
2022-03-07 12:04:20 +00:00
|
|
|
DivPlatformSwan::~DivPlatformSwan() {
|
2022-03-06 16:13:47 +00:00
|
|
|
}
|