2022-02-21 19:17:16 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-20 17:15:15 +00:00
|
|
|
#include "lynx.h"
|
|
|
|
#include "../engine.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define rWrite(a,v) {if (!skipRegisterWrites) {mikey->write(a,v); if (dumpWrites) {addWrite(a,v);}}}
|
|
|
|
|
|
|
|
#define WRITE_VOLUME(ch,v) rWrite(0x20+(ch<<3),(v))
|
|
|
|
#define WRITE_FEEDBACK(ch,v) rWrite(0x21+(ch<<3),(v))
|
2022-05-27 06:10:34 +00:00
|
|
|
#define WRITE_OUTPUT(ch,v) rWrite(0x22+(ch<<3),(v))
|
2022-02-20 17:15:15 +00:00
|
|
|
#define WRITE_LFSR(ch,v) rWrite(0x23+(ch<<3),(v))
|
|
|
|
#define WRITE_BACKUP(ch,v) rWrite(0x24+(ch<<3),(v))
|
|
|
|
#define WRITE_CONTROL(ch,v) rWrite(0x25+(ch<<3),(v))
|
|
|
|
#define WRITE_OTHER(ch,v) rWrite(0x27+(ch<<3),(v))
|
2022-02-21 11:41:06 +00:00
|
|
|
#define WRITE_ATTEN(ch,v) rWrite((0x40+ch),(v))
|
2022-02-24 21:53:20 +00:00
|
|
|
#define WRITE_STEREO(v) rWrite(0x50,(v))
|
2022-02-20 17:15:15 +00:00
|
|
|
|
|
|
|
#define CHIP_DIVIDER 64
|
2022-09-23 16:04:09 +00:00
|
|
|
#define CHIP_FREQBASE 16000000
|
2022-02-20 17:15:15 +00:00
|
|
|
|
|
|
|
#if defined( _MSC_VER )
|
|
|
|
|
|
|
|
#include <intrin.h>
|
|
|
|
|
|
|
|
static int bsr(uint16_t v) {
|
|
|
|
unsigned long idx;
|
|
|
|
if (_BitScanReverse(&idx,(unsigned long)v)) {
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined( __GNUC__ )
|
|
|
|
|
|
|
|
static int bsr(uint16_t v)
|
|
|
|
{
|
|
|
|
if (v) {
|
2022-02-23 21:48:06 +00:00
|
|
|
return 32 - __builtin_clz(v);
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
static int bsr(uint16_t v)
|
|
|
|
{
|
|
|
|
uint16_t mask = 0x8000;
|
2022-02-23 21:48:06 +00:00
|
|
|
for (int i = 15; i >= 0; --i) {
|
2022-02-20 17:15:15 +00:00
|
|
|
if (v&mask)
|
|
|
|
return (int)i;
|
|
|
|
mask>>=1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int32_t clamp(int32_t v, int32_t lo, int32_t hi)
|
|
|
|
{
|
|
|
|
return v<lo?lo:(v>hi?hi:v);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* regCheatSheetLynx[]={
|
2022-03-10 16:36:27 +00:00
|
|
|
"AUDIO0_VOLCNTRL", "20",
|
|
|
|
"AUDIO0_FEEDBACK", "21",
|
|
|
|
"AUDIO0_OUTPUT", "22",
|
|
|
|
"AUDIO0_SHIFT", "23",
|
|
|
|
"AUDIO0_BACKUP", "24",
|
|
|
|
"AUDIO0_CONTROL", "25",
|
|
|
|
"AUDIO0_COUNTER", "26",
|
|
|
|
"AUDIO0_OTHER", "27",
|
|
|
|
"AUDIO1_VOLCNTRL", "28",
|
|
|
|
"AUDIO1_FEEDBACK", "29",
|
|
|
|
"AUDIO1_OUTPUT", "2a",
|
|
|
|
"AUDIO1_SHIFT", "2b",
|
|
|
|
"AUDIO1_BACKUP", "2c",
|
|
|
|
"AUDIO1_CONTROL", "2d",
|
|
|
|
"AUDIO1_COUNTER", "2e",
|
|
|
|
"AUDIO1_OTHER", "2f",
|
|
|
|
"AUDIO2_VOLCNTRL", "30",
|
|
|
|
"AUDIO2_FEEDBACK", "31",
|
|
|
|
"AUDIO2_OUTPUT", "32",
|
|
|
|
"AUDIO2_SHIFT", "33",
|
|
|
|
"AUDIO2_BACKUP", "34",
|
|
|
|
"AUDIO2_CONTROL", "35",
|
|
|
|
"AUDIO2_COUNTER", "36",
|
|
|
|
"AUDIO2_OTHER", "37",
|
|
|
|
"AUDIO3_VOLCNTRL", "38",
|
|
|
|
"AUDIO3_FEEDBACK", "39",
|
|
|
|
"AUDIO3_OUTPUT", "3a",
|
|
|
|
"AUDIO3_SHIFT", "3b",
|
|
|
|
"AUDIO3_BACKUP", "3c",
|
|
|
|
"AUDIO3_CONTROL", "3d",
|
|
|
|
"AUDIO3_COUNTER", "3e",
|
|
|
|
"AUDIO3_OTHER", "3f",
|
|
|
|
"ATTENREG0", "40",
|
|
|
|
"ATTENREG1", "41",
|
|
|
|
"ATTENREG2", "42",
|
|
|
|
"ATTENREG3", "43",
|
|
|
|
"MPAN", "44",
|
|
|
|
"MSTEREO", "50",
|
2022-02-20 17:15:15 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const char** DivPlatformLynx::getRegisterSheet() {
|
|
|
|
return regCheatSheetLynx;
|
2022-02-24 21:53:20 +00:00
|
|
|
}
|
|
|
|
|
2023-01-02 09:53:37 +00:00
|
|
|
void DivPlatformLynx::acquire(short** buf, size_t len) {
|
2023-01-03 06:09:46 +00:00
|
|
|
for (size_t h=0; h<len; h++) {
|
2022-05-26 05:29:04 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
if (chan[i].pcm && chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
|
|
|
|
chan[i].sampleAccum-=chan[i].sampleFreq;
|
|
|
|
if (chan[i].sampleAccum<0) {
|
|
|
|
chan[i].sampleAccum+=rate;
|
|
|
|
DivSample* s=parent->getSample(chan[i].sample);
|
|
|
|
if (s!=NULL) {
|
|
|
|
if (isMuted[i]) {
|
2022-05-27 06:10:34 +00:00
|
|
|
WRITE_OUTPUT(i,0);
|
2022-05-26 05:29:04 +00:00
|
|
|
} else {
|
2022-09-23 16:04:09 +00:00
|
|
|
WRITE_OUTPUT(i,CLAMP((s->data8[chan[i].samplePos]*chan[i].outVol)>>7,-128,127));
|
2022-05-26 05:29:04 +00:00
|
|
|
}
|
2022-09-23 16:04:09 +00:00
|
|
|
chan[i].samplePos++;
|
2022-05-27 06:36:05 +00:00
|
|
|
|
2022-08-28 01:50:57 +00:00
|
|
|
if (s->isLoopable() && chan[i].samplePos>=s->loopEnd) {
|
|
|
|
chan[i].samplePos=s->loopStart;
|
|
|
|
} else if (chan[i].samplePos>=(int)s->samples) {
|
2022-07-22 04:36:42 +00:00
|
|
|
chan[i].sample=-1;
|
2022-05-26 05:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 06:09:46 +00:00
|
|
|
mikey->sampleAudio(buf[0]+h,buf[1]+h,1,oscBuf);
|
2022-05-26 05:29:04 +00:00
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-15 20:01:11 +00:00
|
|
|
void DivPlatformLynx::tick(bool sysTick) {
|
2022-02-20 17:15:15 +00:00
|
|
|
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) {
|
2022-05-27 06:20:57 +00:00
|
|
|
if (chan[i].pcm) {
|
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
|
|
|
chan[i].outVol=((chan[i].vol&127)*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/chan[i].macroVolMul;
|
2022-05-27 06:20:57 +00:00
|
|
|
} else {
|
|
|
|
chan[i].outVol=((chan[i].vol&127)*MIN(127,chan[i].std.vol.val))>>7;
|
|
|
|
}
|
2022-05-27 06:10:34 +00:00
|
|
|
WRITE_VOLUME(i,(isMuted[i]?0:(chan[i].outVol&127)));
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
2022-12-17 06:21:08 +00:00
|
|
|
if (NEW_ARP_STRAT) {
|
|
|
|
chan[i].handleArp();
|
|
|
|
} else if (chan[i].std.arp.had) {
|
2022-02-20 17:15:15 +00:00
|
|
|
if (!chan[i].inPorta) {
|
2022-08-22 20:59:45 +00:00
|
|
|
chan[i].actualNote=parent->calcArp(chan[i].note,chan[i].std.arp.val);
|
|
|
|
chan[i].baseFreq=NOTE_PERIODIC(chan[i].actualNote);
|
2022-08-27 08:25:48 +00:00
|
|
|
if (chan[i].pcm) chan[i].sampleBaseFreq=NOTE_FREQUENCY(chan[i].actualNote);
|
2022-02-20 17:15:15 +00:00
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
WRITE_ATTEN(i,chan[i].pan);
|
|
|
|
}
|
|
|
|
|
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-05-25 05:28:47 +00:00
|
|
|
if (chan[i].std.phaseReset.had) {
|
|
|
|
if (chan[i].std.phaseReset.val==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 (chan[i].pcm && chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
|
|
|
|
chan[i].sampleAccum=0;
|
|
|
|
chan[i].samplePos=0;
|
|
|
|
}
|
2022-05-25 05:28:47 +00:00
|
|
|
WRITE_LFSR(i, 0);
|
|
|
|
WRITE_OTHER(i, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:15:15 +00:00
|
|
|
if (chan[i].freqChanged) {
|
2022-05-26 05:29:04 +00:00
|
|
|
if (chan[i].pcm) {
|
|
|
|
double off=1.0;
|
|
|
|
if (chan[i].sample>=0 && chan[i].sample<parent->song.sampleLen) {
|
|
|
|
DivSample* s=parent->getSample(chan[i].sample);
|
|
|
|
if (s->centerRate<1) {
|
|
|
|
off=1.0;
|
|
|
|
} else {
|
|
|
|
off=(double)s->centerRate/8363.0;
|
|
|
|
}
|
|
|
|
}
|
2022-12-17 07:07:24 +00:00
|
|
|
chan[i].sampleFreq=off*parent->calcFreq(chan[i].sampleBaseFreq,chan[i].pitch,chan[i].fixedArp?chan[i].baseNoteOverride:chan[i].arpOff,chan[i].fixedArp,false,2,chan[i].pitch2,chipClock,CHIP_FREQBASE);
|
2022-05-26 05:29:04 +00:00
|
|
|
} else {
|
|
|
|
if (chan[i].lfsr >= 0) {
|
|
|
|
WRITE_LFSR(i, (chan[i].lfsr&0xff));
|
|
|
|
WRITE_OTHER(i, ((chan[i].lfsr&0xf00)>>4));
|
|
|
|
chan[i].lfsr=-1;
|
|
|
|
}
|
2022-12-17 07:07:24 +00:00
|
|
|
chan[i].fd=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-05-26 05:29:04 +00:00
|
|
|
if (chan[i].std.duty.had) {
|
|
|
|
chan[i].duty=chan[i].std.duty.val;
|
|
|
|
WRITE_FEEDBACK(i, chan[i].duty.feedback);
|
|
|
|
}
|
|
|
|
WRITE_CONTROL(i, (chan[i].fd.clockDivider|0x18|chan[i].duty.int_feedback7));
|
|
|
|
WRITE_BACKUP( i, chan[i].fd.backup );
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
2022-04-16 05:39:03 +00:00
|
|
|
chan[i].freqChanged=false;
|
|
|
|
} else if (chan[i].std.duty.had) {
|
2022-04-10 05:01:55 +00:00
|
|
|
chan[i].duty = chan[i].std.duty.val;
|
2022-05-26 05:39:15 +00:00
|
|
|
if (!chan[i].pcm) {
|
|
|
|
WRITE_FEEDBACK(i, chan[i].duty.feedback);
|
|
|
|
WRITE_CONTROL(i, (chan[i].fd.clockDivider|0x18|chan[i].duty.int_feedback7));
|
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformLynx::dispatch(DivCommand c) {
|
|
|
|
switch (c.cmd) {
|
2022-05-26 05:29:04 +00:00
|
|
|
case DIV_CMD_NOTE_ON: {
|
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_MIKEY);
|
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
|
|
|
chan[c.chan].macroVolMul=ins->type==DIV_INS_AMIGA?64:127;
|
|
|
|
chan[c.chan].pcm=(ins->type==DIV_INS_AMIGA || ins->amiga.useSample);
|
2022-02-20 17:15:15 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
|
|
|
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value);
|
2022-05-26 05:29:04 +00:00
|
|
|
if (chan[c.chan].pcm) {
|
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
|
|
|
chan[c.chan].sampleBaseFreq=NOTE_FREQUENCY(c.value);
|
2022-12-29 08:12:00 +00:00
|
|
|
if (c.value!=DIV_NOTE_NULL) chan[c.chan].sample=ins->amiga.getSample(c.value);
|
2022-05-26 05:29:04 +00:00
|
|
|
chan[c.chan].sampleAccum=0;
|
|
|
|
chan[c.chan].samplePos=0;
|
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
chan[c.chan].actualNote=c.value;
|
2022-02-21 11:41:06 +00:00
|
|
|
if (chan[c.chan].lfsr<0)
|
|
|
|
chan[c.chan].lfsr=0;
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
chan[c.chan].active=true;
|
|
|
|
WRITE_VOLUME(c.chan,(isMuted[c.chan]?0:(chan[c.chan].vol&127)));
|
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
|
|
|
chan[c.chan].macroInit(ins);
|
2022-06-01 00:03:26 +00:00
|
|
|
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) {
|
|
|
|
chan[c.chan].outVol=chan[c.chan].vol;
|
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
break;
|
2022-05-26 05:29:04 +00:00
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
chan[c.chan].active=false;
|
2022-05-27 06:10:34 +00:00
|
|
|
WRITE_VOLUME(c.chan,0);
|
|
|
|
WRITE_CONTROL(c.chan,0);
|
2022-04-28 06:31:16 +00:00
|
|
|
chan[c.chan].macroInit(NULL);
|
2022-05-26 05:39:15 +00:00
|
|
|
if (chan[c.chan].pcm) {
|
|
|
|
chan[c.chan].pcm=false;
|
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
break;
|
2022-02-21 11:41:06 +00:00
|
|
|
case DIV_CMD_LYNX_LFSR_LOAD:
|
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].lfsr=c.value;
|
|
|
|
break;
|
2022-02-20 17:15:15 +00:00
|
|
|
case DIV_CMD_NOTE_OFF_ENV:
|
|
|
|
case DIV_CMD_ENV_RELEASE:
|
|
|
|
chan[c.chan].std.release();
|
|
|
|
break;
|
|
|
|
case DIV_CMD_INSTRUMENT:
|
|
|
|
chan[c.chan].ins=c.value;
|
2022-04-28 06:31:16 +00:00
|
|
|
//chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_MIKEY));
|
2022-02-20 17:15:15 +00:00
|
|
|
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) {
|
2022-02-20 17:15:15 +00:00
|
|
|
chan[c.chan].outVol=c.value;
|
|
|
|
}
|
2022-05-26 05:50:11 +00:00
|
|
|
if (chan[c.chan].active && !chan[c.chan].pcm) WRITE_VOLUME(c.chan,(isMuted[c.chan]?0:(chan[c.chan].vol&127)));
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
break;
|
2022-02-21 11:41:06 +00:00
|
|
|
case DIV_CMD_PANNING:
|
2022-04-30 04:41:14 +00:00
|
|
|
chan[c.chan].pan=(c.value&0xf0)|(c.value2>>4);
|
2022-02-24 21:53:20 +00:00
|
|
|
WRITE_ATTEN(c.chan,chan[c.chan].pan);
|
2022-02-21 11:41:06 +00:00
|
|
|
break;
|
2022-02-20 17:15:15 +00:00
|
|
|
case DIV_CMD_GET_VOLUME:
|
2022-04-10 05:01:55 +00:00
|
|
|
if (chan[c.chan].std.vol.has) {
|
2022-02-20 17:15:15 +00:00
|
|
|
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_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;
|
2022-05-26 05:50:11 +00:00
|
|
|
if (chan[c.chan].pcm && parent->song.linearPitch==2) {
|
|
|
|
chan[c.chan].sampleBaseFreq=chan[c.chan].baseFreq;
|
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
if (return2) {
|
|
|
|
chan[c.chan].inPorta=false;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-05-26 08:37:34 +00:00
|
|
|
case DIV_CMD_LEGATO: {
|
2022-12-17 07:07:24 +00:00
|
|
|
int whatAMess=c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0));
|
2022-05-26 08:37:34 +00:00
|
|
|
chan[c.chan].baseFreq=NOTE_PERIODIC(whatAMess);
|
|
|
|
if (chan[c.chan].pcm) {
|
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
|
|
|
chan[c.chan].sampleBaseFreq=NOTE_FREQUENCY(whatAMess);
|
2022-05-26 08:37:34 +00:00
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
chan[c.chan].note=c.value;
|
|
|
|
chan[c.chan].actualNote=c.value;
|
|
|
|
break;
|
2022-05-26 08:37:34 +00:00
|
|
|
}
|
2022-02-20 17:15:15 +00:00
|
|
|
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_MIKEY));
|
2022-02-20 17:15:15 +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-02-20 17:15:15 +00:00
|
|
|
chan[c.chan].inPorta=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 127;
|
|
|
|
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-02-20 17:15:15 +00:00
|
|
|
case DIV_ALWAYS_SET_VOLUME:
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformLynx::muteChannel(int ch, bool mute) {
|
|
|
|
isMuted[ch]=mute;
|
|
|
|
if (chan[ch].active) WRITE_VOLUME(ch,(isMuted[ch]?0:(chan[ch].outVol&127)));
|
|
|
|
}
|
|
|
|
|
2023-01-02 00:46:08 +00:00
|
|
|
int DivPlatformLynx::getOutputCount() {
|
|
|
|
return 2;
|
2022-02-24 21:53:20 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 17:15:15 +00:00
|
|
|
void DivPlatformLynx::forceIns() {
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
if (chan[i].active) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-02-28 07:27:22 +00:00
|
|
|
WRITE_ATTEN(i,chan[i].pan);
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* DivPlatformLynx::getChanState(int ch) {
|
|
|
|
return &chan[ch];
|
2022-02-24 21:53:20 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 23:17:00 +00:00
|
|
|
DivMacroInt* DivPlatformLynx::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* DivPlatformLynx::getOscBuffer(int ch) {
|
|
|
|
return oscBuf[ch];
|
|
|
|
}
|
|
|
|
|
2022-02-24 21:53:20 +00:00
|
|
|
unsigned char* DivPlatformLynx::getRegisterPool()
|
|
|
|
{
|
|
|
|
return const_cast<unsigned char*>( mikey->getRegisterPool() );
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformLynx::getRegisterPoolSize()
|
|
|
|
{
|
|
|
|
return 4*8+4;
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformLynx::reset() {
|
2022-04-15 10:37:23 +00:00
|
|
|
mikey=std::make_unique<Lynx::Mikey>(rate);
|
2022-02-22 20:35:17 +00:00
|
|
|
|
2022-02-20 17:15:15 +00:00
|
|
|
for (int i=0; i<4; i++) {
|
2022-04-15 10:37:23 +00:00
|
|
|
chan[i]=DivPlatformLynx::Channel();
|
|
|
|
chan[i].std.setEngine(parent);
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
if (dumpWrites) {
|
|
|
|
addWrite(0xffffffff,0);
|
|
|
|
}
|
2022-02-24 21:53:20 +00:00
|
|
|
WRITE_STEREO(0);
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DivPlatformLynx::keyOffAffectsArp(int ch) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DivPlatformLynx::keyOffAffectsPorta(int ch) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//int DivPlatformLynx::getPortaFloor(int ch) {
|
|
|
|
// return 12;
|
|
|
|
//}
|
|
|
|
|
|
|
|
void DivPlatformLynx::notifyInsDeletion(void* ins) {
|
|
|
|
for (int i=0; i<4; i++) {
|
|
|
|
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformLynx::poke(unsigned int addr, unsigned short val) {
|
|
|
|
rWrite(addr,val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformLynx::poke(std::vector<DivRegWrite>& wlist) {
|
|
|
|
for (DivRegWrite& i: wlist) rWrite(i.addr, i.val);
|
|
|
|
}
|
|
|
|
|
2022-09-30 01:13:40 +00:00
|
|
|
int DivPlatformLynx::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
2022-02-20 17:15:15 +00:00
|
|
|
parent=p;
|
|
|
|
dumpWrites=false;
|
|
|
|
skipRegisterWrites=false;
|
|
|
|
|
|
|
|
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;
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chipClock = 16000000;
|
2022-12-04 07:04:42 +00:00
|
|
|
CHECK_CUSTOM_CLOCK;
|
2022-02-20 17:15:15 +00:00
|
|
|
rate = chipClock/128;
|
|
|
|
|
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]->rate=rate;
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:15:15 +00:00
|
|
|
reset();
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformLynx::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-02-20 17:15:15 +00:00
|
|
|
mikey.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformLynx::~DivPlatformLynx() {
|
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformLynx::MikeyFreqDiv::MikeyFreqDiv(int frequency) {
|
|
|
|
|
|
|
|
int clamped=clamp(frequency, 36, 16383);
|
|
|
|
|
|
|
|
auto top=bsr(clamped);
|
|
|
|
|
|
|
|
if (top>7)
|
|
|
|
{
|
|
|
|
clockDivider=top-7;
|
2023-01-13 06:22:15 +00:00
|
|
|
backup=clamped>>(top-7);
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clockDivider=0;
|
2023-01-13 06:22:15 +00:00
|
|
|
backup=clamped;
|
2022-02-20 17:15:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformLynx::MikeyDuty::MikeyDuty(int duty) {
|
|
|
|
|
|
|
|
//duty:
|
|
|
|
//9: int
|
|
|
|
//8: f11
|
|
|
|
//7: f10
|
|
|
|
//6: f7
|
|
|
|
//5: f5
|
|
|
|
//4: f4
|
|
|
|
//3: f3
|
|
|
|
//2: f2
|
|
|
|
//1: f1
|
|
|
|
//0: f0
|
|
|
|
|
|
|
|
//f7 moved to bit 7 and int moved to bit 5
|
|
|
|
int_feedback7=((duty&0x40)<<1)|((duty&0x200)>>4);
|
|
|
|
//f11 and f10 moved to bits 7 & 6
|
|
|
|
feedback=(duty&0x3f)|((duty&0x180)>>1);
|
|
|
|
}
|