2022-02-15 03:12:20 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2023-01-20 00:18:40 +00:00
|
|
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
2022-02-15 03:12:20 +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.
|
|
|
|
*/
|
|
|
|
|
2021-12-05 04:55:28 +00:00
|
|
|
#include "c64.h"
|
|
|
|
#include "../engine.h"
|
2022-08-29 08:26:49 +00:00
|
|
|
#include "sound/c64_fp/siddefs-fp.h"
|
2021-12-05 04:55:28 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2022-12-11 21:46:25 +00:00
|
|
|
#define rWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} }
|
2021-12-21 06:29:07 +00:00
|
|
|
|
2022-01-28 05:55:51 +00:00
|
|
|
#define CHIP_FREQBASE 524288
|
|
|
|
|
2022-02-02 07:14:42 +00:00
|
|
|
const char* regCheatSheetSID[]={
|
|
|
|
"FreqL0", "00",
|
|
|
|
"FreqH0", "01",
|
|
|
|
"PWL0", "02",
|
|
|
|
"PWH0", "03",
|
|
|
|
"Control0", "04",
|
|
|
|
"AtkDcy0", "05",
|
|
|
|
"StnRis0", "06",
|
|
|
|
"FreqL1", "07",
|
|
|
|
"FreqH1", "08",
|
|
|
|
"PWL1", "09",
|
|
|
|
"PWH1", "0A",
|
|
|
|
"Control1", "0B",
|
|
|
|
"AtkDcy1", "0C",
|
|
|
|
"StnRis1", "0D",
|
|
|
|
"FreqL2", "0E",
|
|
|
|
"FreqH2", "0F",
|
|
|
|
"PWL2", "10",
|
|
|
|
"PWH2", "11",
|
|
|
|
"Control2", "12",
|
|
|
|
"AtkDcy2", "13",
|
|
|
|
"StnRis2", "14",
|
|
|
|
"FCL", "15",
|
|
|
|
"FCH", "16",
|
|
|
|
"FilterRes", "17",
|
|
|
|
"FilterMode", "18",
|
|
|
|
"PotX", "19",
|
|
|
|
"PotY", "1A",
|
|
|
|
"Osc3", "1B",
|
|
|
|
"Env3", "1C",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2022-02-03 23:38:57 +00:00
|
|
|
const char** DivPlatformC64::getRegisterSheet() {
|
|
|
|
return regCheatSheetSID;
|
|
|
|
}
|
|
|
|
|
2023-01-02 09:53:37 +00:00
|
|
|
void DivPlatformC64::acquire(short** buf, size_t len) {
|
2022-08-29 08:26:49 +00:00
|
|
|
int dcOff=isFP?0:sid.get_dc(0);
|
2023-01-02 09:53:37 +00:00
|
|
|
for (size_t i=0; i<len; i++) {
|
2022-12-11 21:46:25 +00:00
|
|
|
if (!writes.empty()) {
|
|
|
|
QueuedWrite w=writes.front();
|
|
|
|
if (isFP) {
|
|
|
|
sid_fp.write(w.addr,w.val);
|
|
|
|
} else {
|
|
|
|
sid.write(w.addr,w.val);
|
|
|
|
};
|
|
|
|
regPool[w.addr&0x1f]=w.val;
|
|
|
|
writes.pop();
|
|
|
|
}
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
2023-01-02 09:53:37 +00:00
|
|
|
sid_fp.clock(4,&buf[0][i]);
|
2022-08-29 08:54:55 +00:00
|
|
|
if (++writeOscBuf>=4) {
|
|
|
|
writeOscBuf=0;
|
|
|
|
oscBuf[0]->data[oscBuf[0]->needle++]=(sid_fp.lastChanOut[0]-dcOff)>>5;
|
|
|
|
oscBuf[1]->data[oscBuf[1]->needle++]=(sid_fp.lastChanOut[1]-dcOff)>>5;
|
|
|
|
oscBuf[2]->data[oscBuf[2]->needle++]=(sid_fp.lastChanOut[2]-dcOff)>>5;
|
|
|
|
}
|
2022-08-29 08:26:49 +00:00
|
|
|
} else {
|
|
|
|
sid.clock();
|
2023-01-02 09:53:37 +00:00
|
|
|
buf[0][i]=sid.output();
|
2022-08-29 08:54:55 +00:00
|
|
|
if (++writeOscBuf>=16) {
|
2022-08-29 08:26:49 +00:00
|
|
|
writeOscBuf=0;
|
|
|
|
oscBuf[0]->data[oscBuf[0]->needle++]=(sid.last_chan_out[0]-dcOff)>>5;
|
|
|
|
oscBuf[1]->data[oscBuf[1]->needle++]=(sid.last_chan_out[1]-dcOff)>>5;
|
|
|
|
oscBuf[2]->data[oscBuf[2]->needle++]=(sid.last_chan_out[2]-dcOff)>>5;
|
|
|
|
}
|
2022-04-30 19:36:12 +00:00
|
|
|
}
|
2021-12-06 10:21:42 +00:00
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
|
|
|
|
2021-12-07 06:23:57 +00:00
|
|
|
void DivPlatformC64::updateFilter() {
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(0x15,filtCut&7);
|
|
|
|
rWrite(0x16,filtCut>>3);
|
2022-03-31 18:46:27 +00:00
|
|
|
rWrite(0x17,(filtRes<<4)|(chan[2].filter<<2)|(chan[1].filter<<1)|(int)(chan[0].filter));
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(0x18,(filtControl<<4)|vol);
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 20:01:11 +00:00
|
|
|
void DivPlatformC64::tick(bool sysTick) {
|
2021-12-05 04:55:28 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
chan[i].std.next();
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.vol.had) {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_C64);
|
2021-12-07 06:23:57 +00:00
|
|
|
if (ins->c64.volIsCutoff) {
|
2022-01-10 22:04:31 +00:00
|
|
|
if (ins->c64.filterIsAbs) {
|
2022-04-10 05:01:55 +00:00
|
|
|
filtCut=MIN(2047,chan[i].std.vol.val);
|
2022-01-10 22:04:31 +00:00
|
|
|
} else {
|
2022-04-25 22:55:48 +00:00
|
|
|
filtCut-=((signed char)chan[i].std.vol.val)*7;
|
2022-01-10 22:04:31 +00:00
|
|
|
if (filtCut>2047) filtCut=2047;
|
|
|
|
if (filtCut<0) filtCut=0;
|
|
|
|
}
|
2021-12-07 06:23:57 +00:00
|
|
|
updateFilter();
|
|
|
|
} else {
|
2022-04-10 05:01:55 +00:00
|
|
|
vol=MIN(15,chan[i].std.vol.val);
|
2021-12-07 06:23:57 +00:00
|
|
|
updateFilter();
|
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
2022-12-17 06:21:08 +00:00
|
|
|
if (NEW_ARP_STRAT) {
|
|
|
|
chan[i].handleArp();
|
|
|
|
} else if (chan[i].std.arp.had) {
|
2021-12-07 21:25:42 +00:00
|
|
|
if (!chan[i].inPorta) {
|
2022-08-22 20:59:45 +00:00
|
|
|
chan[i].baseFreq=NOTE_FREQUENCY(parent->calcArp(chan[i].note,chan[i].std.arp.val));
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.duty.had) {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_C64);
|
2022-04-10 21:53:43 +00:00
|
|
|
if (ins->c64.dutyIsAbs) {
|
2022-04-10 05:01:55 +00:00
|
|
|
chan[i].duty=chan[i].std.duty.val;
|
2022-01-10 21:54:58 +00:00
|
|
|
} else {
|
2022-04-25 22:55:48 +00:00
|
|
|
chan[i].duty-=((signed char)chan[i].std.duty.val)*4;
|
2022-01-10 21:54:58 +00:00
|
|
|
}
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(i*7+2,chan[i].duty&0xff);
|
|
|
|
rWrite(i*7+3,chan[i].duty>>8);
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.wave.had) {
|
|
|
|
chan[i].wave=chan[i].std.wave.val;
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1)|(int)(chan[i].active));
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
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;
|
2023-01-13 06:10:57 +00:00
|
|
|
CLAMP_VAR(chan[i].pitch2,-65535,65535);
|
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-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.ex1.had) {
|
|
|
|
filtControl=chan[i].std.ex1.val&15;
|
2022-02-06 20:44:06 +00:00
|
|
|
updateFilter();
|
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.ex2.had) {
|
|
|
|
filtRes=chan[i].std.ex2.val&15;
|
2022-02-06 20:44:06 +00:00
|
|
|
updateFilter();
|
|
|
|
}
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[i].std.ex3.had) {
|
|
|
|
chan[i].sync=chan[i].std.ex3.val&1;
|
|
|
|
chan[i].ring=chan[i].std.ex3.val&2;
|
2022-02-06 20:56:10 +00:00
|
|
|
chan[i].freqChanged=true;
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1)|(int)(chan[i].active));
|
|
|
|
}
|
|
|
|
if (chan[i].std.ex4.had) {
|
|
|
|
chan[i].test=chan[i].std.ex4.val&1;
|
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1)|(int)(chan[i].active));
|
2022-02-06 20:56:10 +00:00
|
|
|
}
|
|
|
|
|
2022-10-07 22:21:53 +00:00
|
|
|
if (sysTick) {
|
|
|
|
if (chan[i].testWhen>0) {
|
|
|
|
if (--chan[i].testWhen<1) {
|
|
|
|
if (!chan[i].resetMask && !chan[i].inPorta) {
|
|
|
|
DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_C64);
|
|
|
|
rWrite(i*7+5,0);
|
|
|
|
rWrite(i*7+6,0);
|
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(ins->c64.noTest?0:8)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-05 04:55:28 +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,false,8,chan[i].pitch2,chipClock,CHIP_FREQBASE);
|
2023-01-13 06:10:57 +00:00
|
|
|
if (chan[i].freq<0) chan[i].freq=0;
|
2021-12-06 08:26:39 +00:00
|
|
|
if (chan[i].freq>0xffff) chan[i].freq=0xffff;
|
2021-12-05 04:55:28 +00:00
|
|
|
if (chan[i].keyOn) {
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(i*7+5,(chan[i].attack<<4)|(chan[i].decay));
|
|
|
|
rWrite(i*7+6,(chan[i].sustain<<4)|(chan[i].release));
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1)|1);
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
2022-04-15 06:20:09 +00:00
|
|
|
if (chan[i].keyOff) {
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(i*7+5,(chan[i].attack<<4)|(chan[i].decay));
|
|
|
|
rWrite(i*7+6,(chan[i].sustain<<4)|(chan[i].release));
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(i*7+4,(chan[i].wave<<4)|(chan[i].test<<3)|(chan[i].ring<<2)|(chan[i].sync<<1)|0);
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(i*7,chan[i].freq&0xff);
|
|
|
|
rWrite(i*7+1,chan[i].freq>>8);
|
2021-12-05 04:55:28 +00:00
|
|
|
if (chan[i].keyOn) chan[i].keyOn=false;
|
|
|
|
if (chan[i].keyOff) chan[i].keyOff=false;
|
|
|
|
chan[i].freqChanged=false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformC64::dispatch(DivCommand c) {
|
|
|
|
switch (c.cmd) {
|
2021-12-05 21:45:29 +00:00
|
|
|
case DIV_CMD_NOTE_ON: {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_C64);
|
2022-01-19 05:01:34 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
2022-01-28 05:55:51 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value);
|
2022-01-19 05:01:34 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
chan[c.chan].active=true;
|
|
|
|
chan[c.chan].keyOn=true;
|
2022-04-28 04:54:45 +00:00
|
|
|
chan[c.chan].test=false;
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[c.chan].insChanged || chan[c.chan].resetDuty || ins->std.waveMacro.len>0) {
|
2022-01-09 22:00:52 +00:00
|
|
|
chan[c.chan].duty=ins->c64.duty;
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(c.chan*7+2,chan[c.chan].duty&0xff);
|
|
|
|
rWrite(c.chan*7+3,chan[c.chan].duty>>8);
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
|
|
|
if (chan[c.chan].insChanged) {
|
2022-03-31 18:46:27 +00:00
|
|
|
chan[c.chan].wave=(ins->c64.noiseOn<<3)|(ins->c64.pulseOn<<2)|(ins->c64.sawOn<<1)|(int)(ins->c64.triOn);
|
2021-12-07 06:23:57 +00:00
|
|
|
chan[c.chan].attack=ins->c64.a;
|
2022-01-20 03:58:37 +00:00
|
|
|
chan[c.chan].decay=(ins->c64.s==15)?0:ins->c64.d;
|
2021-12-07 06:23:57 +00:00
|
|
|
chan[c.chan].sustain=ins->c64.s;
|
|
|
|
chan[c.chan].release=ins->c64.r;
|
|
|
|
chan[c.chan].ring=ins->c64.ringMod;
|
|
|
|
chan[c.chan].sync=ins->c64.oscSync;
|
|
|
|
}
|
|
|
|
if (chan[c.chan].insChanged || chan[c.chan].resetFilter) {
|
|
|
|
chan[c.chan].filter=ins->c64.toFilter;
|
|
|
|
if (ins->c64.initFilter) {
|
2022-01-09 22:00:52 +00:00
|
|
|
filtCut=ins->c64.cut;
|
2021-12-07 06:23:57 +00:00
|
|
|
filtRes=ins->c64.res;
|
2022-03-31 18:46:27 +00:00
|
|
|
filtControl=(int)(ins->c64.lp)|(ins->c64.bp<<1)|(ins->c64.hp<<2)|(ins->c64.ch3off<<3);
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
2022-02-21 03:48:42 +00:00
|
|
|
updateFilter();
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
|
|
|
if (chan[c.chan].insChanged) {
|
|
|
|
chan[c.chan].insChanged=false;
|
|
|
|
}
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[c.chan].macroInit(ins);
|
2021-12-05 04:55:28 +00:00
|
|
|
break;
|
2021-12-05 21:45:29 +00:00
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].keyOff=true;
|
2022-02-21 02:39:14 +00:00
|
|
|
chan[c.chan].keyOn=false;
|
2022-04-28 06:31:16 +00:00
|
|
|
//chan[c.chan].macroInit(NULL);
|
2021-12-05 04:55:28 +00:00
|
|
|
break;
|
2022-02-08 18:11:04 +00:00
|
|
|
case DIV_CMD_NOTE_OFF_ENV:
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].keyOff=true;
|
2022-02-21 02:39:14 +00:00
|
|
|
chan[c.chan].keyOn=false;
|
2022-02-08 18:11:04 +00:00
|
|
|
chan[c.chan].std.release();
|
|
|
|
break;
|
|
|
|
case DIV_CMD_ENV_RELEASE:
|
|
|
|
chan[c.chan].std.release();
|
|
|
|
break;
|
2021-12-05 04:55:28 +00:00
|
|
|
case DIV_CMD_INSTRUMENT:
|
2022-01-17 23:01:40 +00:00
|
|
|
if (chan[c.chan].ins!=c.value || c.value2==1) {
|
2021-12-07 06:23:57 +00:00
|
|
|
chan[c.chan].insChanged=true;
|
2021-12-05 04:55:28 +00:00
|
|
|
chan[c.chan].ins=c.value;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_VOLUME:
|
|
|
|
if (chan[c.chan].vol!=c.value) {
|
|
|
|
chan[c.chan].vol=c.value;
|
2022-04-10 05:01:55 +00:00
|
|
|
if (!chan[c.chan].std.vol.has) {
|
2021-12-05 04:55:28 +00:00
|
|
|
chan[c.chan].outVol=c.value;
|
2021-12-07 06:23:57 +00:00
|
|
|
vol=chan[c.chan].outVol;
|
2021-12-05 04:55:28 +00:00
|
|
|
} else {
|
2021-12-07 06:23:57 +00:00
|
|
|
vol=chan[c.chan].vol;
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
2021-12-07 06:23:57 +00:00
|
|
|
updateFilter();
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
|
|
|
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_NOTE_PORTA: {
|
2022-01-28 05:55:51 +00:00
|
|
|
int destFreq=NOTE_FREQUENCY(c.value2);
|
2021-12-05 04:55:28 +00:00
|
|
|
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:
|
2021-12-07 06:23:57 +00:00
|
|
|
chan[c.chan].duty=(c.value*4095)/100;
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(c.chan*7+2,chan[c.chan].duty&0xff);
|
|
|
|
rWrite(c.chan*7+3,chan[c.chan].duty>>8);
|
2021-12-07 06:23:57 +00:00
|
|
|
break;
|
2022-01-11 23:38:26 +00:00
|
|
|
case DIV_CMD_C64_FINE_DUTY:
|
|
|
|
chan[c.chan].duty=c.value;
|
|
|
|
rWrite(c.chan*7+2,chan[c.chan].duty&0xff);
|
|
|
|
rWrite(c.chan*7+3,chan[c.chan].duty>>8);
|
|
|
|
break;
|
2021-12-07 06:23:57 +00:00
|
|
|
case DIV_CMD_WAVE:
|
|
|
|
chan[c.chan].wave=c.value;
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].test<<3)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active));
|
2021-12-05 04:55:28 +00:00
|
|
|
break;
|
|
|
|
case DIV_CMD_LEGATO:
|
2022-12-17 07:07:24 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0)));
|
2021-12-05 04:55:28 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_PRE_PORTA:
|
2022-02-09 03:49:52 +00:00
|
|
|
if (chan[c.chan].active && c.value2) {
|
2022-04-17 06:37:33 +00:00
|
|
|
if (parent->song.resetMacroOnPorta || !chan[c.chan].inPorta) {
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_C64));
|
2022-02-09 03:46:58 +00:00
|
|
|
chan[c.chan].keyOn=true;
|
|
|
|
}
|
2022-02-08 22:02:27 +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_FREQUENCY(chan[c.chan].note);
|
2021-12-05 04:55:28 +00:00
|
|
|
chan[c.chan].inPorta=c.value;
|
|
|
|
break;
|
2021-12-05 21:11:12 +00:00
|
|
|
case DIV_CMD_PRE_NOTE:
|
2021-12-07 06:23:57 +00:00
|
|
|
if (resetTime) chan[c.chan].testWhen=c.value-resetTime+1;
|
2021-12-05 21:11:12 +00:00
|
|
|
break;
|
2021-12-05 04:55:28 +00:00
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 15;
|
|
|
|
break;
|
2021-12-07 06:23:57 +00:00
|
|
|
case DIV_CMD_C64_CUTOFF:
|
|
|
|
if (c.value>100) c.value=100;
|
|
|
|
filtCut=c.value*2047/100;
|
|
|
|
updateFilter();
|
|
|
|
break;
|
2022-01-11 23:38:26 +00:00
|
|
|
case DIV_CMD_C64_FINE_CUTOFF:
|
|
|
|
filtCut=c.value;
|
|
|
|
updateFilter();
|
|
|
|
break;
|
2021-12-07 06:23:57 +00:00
|
|
|
case DIV_CMD_C64_RESONANCE:
|
|
|
|
if (c.value>15) c.value=15;
|
|
|
|
filtRes=c.value;
|
|
|
|
updateFilter();
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_FILTER_MODE:
|
|
|
|
filtControl=c.value&7;
|
|
|
|
updateFilter();
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_RESET_TIME:
|
|
|
|
resetTime=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_RESET_MASK:
|
|
|
|
chan[c.chan].resetMask=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_FILTER_RESET:
|
|
|
|
if (c.value&15) {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_C64);
|
2022-02-01 08:16:03 +00:00
|
|
|
if (ins->c64.initFilter) {
|
|
|
|
filtCut=ins->c64.cut;
|
|
|
|
updateFilter();
|
|
|
|
}
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
|
|
|
chan[c.chan].resetFilter=c.value>>4;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_DUTY_RESET:
|
|
|
|
if (c.value&15) {
|
2022-04-21 07:24:06 +00:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_C64);
|
2022-01-09 22:00:52 +00:00
|
|
|
chan[c.chan].duty=ins->c64.duty;
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(c.chan*7+2,chan[c.chan].duty&0xff);
|
|
|
|
rWrite(c.chan*7+3,chan[c.chan].duty>>8);
|
2021-12-07 06:23:57 +00:00
|
|
|
}
|
|
|
|
chan[c.chan].resetDuty=c.value>>4;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_C64_EXTENDED:
|
|
|
|
switch (c.value>>4) {
|
|
|
|
case 0:
|
|
|
|
chan[c.chan].attack=c.value&15;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
chan[c.chan].decay=c.value&15;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
chan[c.chan].sustain=c.value&15;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
chan[c.chan].release=c.value&15;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
chan[c.chan].ring=c.value;
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].test<<3)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active));
|
2021-12-07 06:23:57 +00:00
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
chan[c.chan].sync=c.value;
|
2022-04-28 04:54:45 +00:00
|
|
|
rWrite(c.chan*7+4,(chan[c.chan].wave<<4)|(chan[c.chan].test<<3)|(chan[c.chan].ring<<2)|(chan[c.chan].sync<<1)|(int)(chan[c.chan].active));
|
2021-12-07 06:23:57 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
filtControl&=7;
|
|
|
|
filtControl|=(!!c.value)<<3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
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;
|
2021-12-05 04:55:28 +00:00
|
|
|
case DIV_ALWAYS_SET_VOLUME:
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-12-18 08:25:42 +00:00
|
|
|
void DivPlatformC64::muteChannel(int ch, bool mute) {
|
|
|
|
isMuted[ch]=mute;
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
|
|
|
sid_fp.mute(ch,mute);
|
|
|
|
} else {
|
|
|
|
sid.set_is_muted(ch,mute);
|
|
|
|
}
|
2021-12-21 06:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformC64::forceIns() {
|
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
chan[i].testWhen=0;
|
2022-02-21 02:39:14 +00:00
|
|
|
if (chan[i].active) {
|
|
|
|
chan[i].keyOn=true;
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2021-12-21 06:29:07 +00:00
|
|
|
}
|
2021-12-28 06:20:48 +00:00
|
|
|
updateFilter();
|
2021-12-18 08:25:42 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 04:59:52 +00:00
|
|
|
void DivPlatformC64::notifyInsChange(int ins) {
|
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
if (chan[i].ins==ins) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:36:02 +00:00
|
|
|
void DivPlatformC64::notifyInsDeletion(void* ins) {
|
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 05:29:16 +00:00
|
|
|
void* DivPlatformC64::getChanState(int ch) {
|
|
|
|
return &chan[ch];
|
|
|
|
}
|
|
|
|
|
2022-06-05 23:17:00 +00:00
|
|
|
DivMacroInt* DivPlatformC64::getChanMacroInt(int ch) {
|
|
|
|
return &chan[ch].std;
|
|
|
|
}
|
|
|
|
|
2022-04-30 19:36:12 +00:00
|
|
|
DivDispatchOscBuffer* DivPlatformC64::getOscBuffer(int ch) {
|
|
|
|
return oscBuf[ch];
|
|
|
|
}
|
|
|
|
|
2022-02-22 03:31:27 +00:00
|
|
|
unsigned char* DivPlatformC64::getRegisterPool() {
|
|
|
|
return regPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformC64::getRegisterPoolSize() {
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
2022-04-15 06:20:09 +00:00
|
|
|
bool DivPlatformC64::getDCOffRequired() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-03 21:21:30 +00:00
|
|
|
bool DivPlatformC64::getWantPreNote() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-08-29 08:26:49 +00:00
|
|
|
float DivPlatformC64::getPostAmp() {
|
|
|
|
return isFP?3.0f:1.0f;
|
|
|
|
}
|
|
|
|
|
2021-12-11 18:14:38 +00:00
|
|
|
void DivPlatformC64::reset() {
|
2022-12-11 21:46:25 +00:00
|
|
|
while (!writes.empty()) writes.pop();
|
2021-12-11 18:14:38 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
chan[i]=DivPlatformC64::Channel();
|
2022-04-15 10:37:23 +00:00
|
|
|
chan[i].std.setEngine(parent);
|
2021-12-11 18:14:38 +00:00
|
|
|
}
|
|
|
|
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
|
|
|
sid_fp.reset();
|
|
|
|
} else {
|
|
|
|
sid.reset();
|
|
|
|
}
|
2022-02-22 03:31:27 +00:00
|
|
|
memset(regPool,0,32);
|
2021-12-11 18:14:38 +00:00
|
|
|
|
2021-12-21 06:29:07 +00:00
|
|
|
rWrite(0x18,0x0f);
|
2021-12-11 18:14:38 +00:00
|
|
|
|
2022-02-21 02:45:28 +00:00
|
|
|
filtControl=7;
|
2021-12-11 18:14:38 +00:00
|
|
|
filtRes=0;
|
2022-02-01 08:16:03 +00:00
|
|
|
filtCut=2047;
|
2021-12-11 18:14:38 +00:00
|
|
|
resetTime=1;
|
|
|
|
vol=15;
|
|
|
|
}
|
|
|
|
|
2022-02-01 23:08:19 +00:00
|
|
|
void DivPlatformC64::poke(unsigned int addr, unsigned short val) {
|
|
|
|
rWrite(addr,val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformC64::poke(std::vector<DivRegWrite>& wlist) {
|
|
|
|
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
|
|
|
}
|
|
|
|
|
2021-12-05 04:55:28 +00:00
|
|
|
void DivPlatformC64::setChipModel(bool is6581) {
|
|
|
|
if (is6581) {
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
|
|
|
sid_fp.setChipModel(reSIDfp::MOS6581);
|
|
|
|
} else {
|
|
|
|
sid.set_chip_model(MOS6581);
|
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
} else {
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
|
|
|
sid_fp.setChipModel(reSIDfp::MOS8580);
|
|
|
|
} else {
|
|
|
|
sid.set_chip_model(MOS8580);
|
|
|
|
}
|
2021-12-05 04:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-29 08:26:49 +00:00
|
|
|
void DivPlatformC64::setFP(bool fp) {
|
|
|
|
isFP=fp;
|
|
|
|
}
|
|
|
|
|
2022-09-30 01:13:40 +00:00
|
|
|
void DivPlatformC64::setFlags(const DivConfig& flags) {
|
|
|
|
switch (flags.getInt("clockSel",0)) {
|
2022-03-02 18:12:10 +00:00
|
|
|
case 0x0: // NTSC C64
|
2022-12-04 07:04:42 +00:00
|
|
|
chipClock=COLOR_NTSC*2.0/7.0;
|
2022-03-02 18:12:10 +00:00
|
|
|
break;
|
|
|
|
case 0x1: // PAL C64
|
2022-12-04 07:04:42 +00:00
|
|
|
chipClock=COLOR_PAL*2.0/9.0;
|
2022-03-02 18:12:10 +00:00
|
|
|
break;
|
|
|
|
case 0x2: // SSI 2001
|
|
|
|
default:
|
2022-12-04 07:04:42 +00:00
|
|
|
chipClock=14318180.0/16.0;
|
2022-03-02 18:12:10 +00:00
|
|
|
break;
|
2021-12-08 06:56:40 +00:00
|
|
|
}
|
2022-12-04 07:04:42 +00:00
|
|
|
CHECK_CUSTOM_CLOCK;
|
|
|
|
rate=chipClock;
|
2022-04-30 19:36:12 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
oscBuf[i]->rate=rate/16;
|
|
|
|
}
|
2022-08-29 08:26:49 +00:00
|
|
|
if (isFP) {
|
|
|
|
rate/=4;
|
|
|
|
sid_fp.setSamplingParameters(chipClock,reSIDfp::DECIMATE,rate,0);
|
|
|
|
}
|
2021-12-15 22:32:08 +00:00
|
|
|
}
|
|
|
|
|
2022-09-30 01:13:40 +00:00
|
|
|
int DivPlatformC64::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
2021-12-15 22:32:08 +00:00
|
|
|
parent=p;
|
2022-01-17 04:21:27 +00:00
|
|
|
dumpWrites=false;
|
2021-12-21 21:02:31 +00:00
|
|
|
skipRegisterWrites=false;
|
2022-04-30 19:36:12 +00:00
|
|
|
writeOscBuf=0;
|
2021-12-18 08:25:42 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
isMuted[i]=false;
|
2022-04-30 19:36:12 +00:00
|
|
|
oscBuf[i]=new DivDispatchOscBuffer;
|
2021-12-18 08:25:42 +00:00
|
|
|
}
|
2022-01-28 17:59:53 +00:00
|
|
|
setFlags(flags);
|
2021-12-05 04:55:28 +00:00
|
|
|
|
2021-12-11 18:14:38 +00:00
|
|
|
reset();
|
2021-12-07 06:23:57 +00:00
|
|
|
|
2021-12-05 04:55:28 +00:00
|
|
|
return 3;
|
|
|
|
}
|
2021-12-15 05:37:27 +00:00
|
|
|
|
|
|
|
void DivPlatformC64::quit() {
|
2022-04-30 19:36:12 +00:00
|
|
|
for (int i=0; i<3; i++) {
|
|
|
|
delete oscBuf[i];
|
|
|
|
}
|
2021-12-15 05:37:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformC64::~DivPlatformC64() {
|
2022-01-17 18:29:35 +00:00
|
|
|
}
|