2022-03-22 12:48:45 -04:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2024-01-16 21:26:57 -05:00
|
|
|
* Copyright (C) 2021-2024 tildearrow and contributors
|
2022-03-22 12:48:45 -04: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "n163.h"
|
|
|
|
#include "../engine.h"
|
2023-03-16 05:21:52 -04:00
|
|
|
#include "../../ta-log.h"
|
2022-03-22 12:48:45 -04:00
|
|
|
#include <math.h>
|
|
|
|
|
2023-07-13 05:09:20 -04:00
|
|
|
#define rWrite(a,v) if (!skipRegisterWrites) {writes.push(QueuedWrite(a,v)); if (dumpWrites) {addWrite(a,v);} }
|
|
|
|
#define rWriteMask(a,v,m) if (!skipRegisterWrites) {writes.push(QueuedWrite(a,v,m)); if (dumpWrites) {addWrite(a,v);} }
|
2022-03-22 12:48:45 -04:00
|
|
|
#define chWrite(c,a,v) \
|
|
|
|
if (c<=chanMax) { \
|
|
|
|
rWrite(0x78-(c<<3)+(a&7),v) \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define chWriteMask(c,a,v,m) \
|
|
|
|
if (c<=chanMax) { \
|
|
|
|
rWriteMask(0x78-(c<<3)+(a&7),v,m) \
|
|
|
|
}
|
|
|
|
|
2023-07-23 16:57:25 -04:00
|
|
|
#define CHIP_FREQBASE (15*524288)
|
2022-03-22 12:48:45 -04:00
|
|
|
|
|
|
|
const char* regCheatSheetN163[]={
|
|
|
|
"FreqL7", "40",
|
|
|
|
"AccL7", "41",
|
|
|
|
"FreqM7", "42",
|
|
|
|
"AccM7", "43",
|
|
|
|
"WavLen_FreqH7", "44",
|
|
|
|
"AccH7", "45",
|
|
|
|
"WavPos7", "46",
|
|
|
|
"Vol7", "47",
|
|
|
|
"FreqL6", "48",
|
|
|
|
"AccL6", "49",
|
|
|
|
"FreqM6", "4A",
|
|
|
|
"AccM6", "4B",
|
|
|
|
"WavLen_FreqH6", "4C",
|
|
|
|
"AccH6", "4D",
|
|
|
|
"WavPos6", "4E",
|
|
|
|
"Vol6", "4F",
|
|
|
|
"FreqL5", "50",
|
|
|
|
"AccL5", "51",
|
|
|
|
"FreqM5", "52",
|
|
|
|
"AccM5", "53",
|
|
|
|
"WavLen_FreqH5", "54",
|
|
|
|
"AccH5", "55",
|
|
|
|
"WavPos5", "56",
|
|
|
|
"Vol5", "57",
|
|
|
|
"FreqL4", "58",
|
|
|
|
"AccL4", "59",
|
|
|
|
"FreqM4", "5A",
|
|
|
|
"AccM4", "5B",
|
|
|
|
"WavLen_FreqH4", "5C",
|
|
|
|
"AccH4", "5D",
|
|
|
|
"WavPos4", "5E",
|
|
|
|
"Vol4", "5F",
|
|
|
|
"FreqL3", "60",
|
|
|
|
"AccL3", "61",
|
|
|
|
"FreqM3", "62",
|
|
|
|
"AccM3", "63",
|
|
|
|
"WavLen_FreqH3", "64",
|
|
|
|
"AccH3", "65",
|
|
|
|
"WavPos3", "66",
|
|
|
|
"Vol3", "67",
|
|
|
|
"FreqL2", "68",
|
|
|
|
"AccL2", "69",
|
|
|
|
"FreqM2", "6A",
|
|
|
|
"AccM2", "6B",
|
|
|
|
"WavLen_FreqH2", "6C",
|
|
|
|
"AccH2", "6D",
|
|
|
|
"WavPos2", "6E",
|
|
|
|
"Vol2", "6F",
|
|
|
|
"FreqL1", "70",
|
|
|
|
"AccL1", "71",
|
|
|
|
"FreqM1", "72",
|
|
|
|
"AccM1", "73",
|
|
|
|
"WavLen_FreqH1", "74",
|
|
|
|
"AccH1", "75",
|
|
|
|
"WavPos1", "76",
|
|
|
|
"Vol1", "77",
|
|
|
|
"FreqL0", "78",
|
|
|
|
"AccL0", "79",
|
|
|
|
"FreqM0", "7A",
|
|
|
|
"AccM0", "7B",
|
|
|
|
"WavLen_FreqH0", "7C",
|
|
|
|
"AccH0", "7D",
|
|
|
|
"WavPos0", "7E",
|
|
|
|
"ChanMax_Vol0", "7F",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
const char** DivPlatformN163::getRegisterSheet() {
|
|
|
|
return regCheatSheetN163;
|
|
|
|
}
|
|
|
|
|
2023-01-02 04:53:37 -05:00
|
|
|
void DivPlatformN163::acquire(short** buf, size_t len) {
|
2023-01-03 01:09:46 -05:00
|
|
|
for (size_t i=0; i<len; i++) {
|
2022-03-28 15:56:35 -04:00
|
|
|
n163.tick();
|
2022-04-01 00:11:02 -04:00
|
|
|
int out=(n163.out()<<6)*2; // scale to 16 bit
|
2022-03-22 12:48:45 -04:00
|
|
|
if (out>32767) out=32767;
|
|
|
|
if (out<-32768) out=-32768;
|
2023-01-12 23:16:33 -05:00
|
|
|
buf[0][i]=out;
|
2022-03-22 12:48:45 -04:00
|
|
|
|
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 03:40:03 -04:00
|
|
|
if (n163.voice_cycle()==0x78) for (int i=0; i<8; i++) {
|
2023-06-18 21:00:20 -04:00
|
|
|
oscBuf[i]->data[oscBuf[i]->needle++]=n163.voice_out(i)<<7;
|
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 03:40:03 -04:00
|
|
|
}
|
|
|
|
|
2022-03-22 12:48:45 -04:00
|
|
|
// command queue
|
|
|
|
while (!writes.empty()) {
|
|
|
|
QueuedWrite w=writes.front();
|
2022-03-28 15:56:35 -04:00
|
|
|
n163.addr_w(w.addr);
|
|
|
|
n163.data_w((n163.data_r()&~w.mask)|(w.val&w.mask));
|
2022-03-22 12:48:45 -04:00
|
|
|
writes.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 01:17:34 -04:00
|
|
|
void DivPlatformN163::updateWave(int ch, int wave, int pos, int len) {
|
2022-03-23 14:53:07 -04:00
|
|
|
len&=0xfc; // 4 nibble boundary
|
2022-04-12 01:17:34 -04:00
|
|
|
if (wave<0) {
|
|
|
|
// load from wave synth
|
2023-08-19 05:38:13 -04:00
|
|
|
if (ch>=0) {
|
|
|
|
for (int i=0; i<len; i++) {
|
|
|
|
unsigned char addr=(pos+i); // address (nibble each)
|
|
|
|
if (addr>=((0x78-(chanMax<<3))<<1)) { // avoid conflict with channel register area
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unsigned char mask=(addr&1)?0xf0:0x0f;
|
|
|
|
int data=chan[ch].ws.output[i];
|
|
|
|
rWriteMask(addr>>1,(addr&1)?(data<<4):(data&0xf),mask);
|
2022-04-12 01:17:34 -04:00
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
2022-04-12 01:17:34 -04:00
|
|
|
} else {
|
|
|
|
// load from custom
|
|
|
|
DivWavetable* wt=parent->getWave(wave);
|
2023-07-21 20:54:35 -04:00
|
|
|
for (int i=0; i<wt->len; i++) {
|
2022-04-12 01:17:34 -04:00
|
|
|
unsigned char addr=(pos+i); // address (nibble each)
|
|
|
|
if (addr>=((0x78-(chanMax<<3))<<1)) { // avoid conflict with channel register area
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
unsigned char mask=(addr&1)?0xf0:0x0f;
|
|
|
|
if (wt->max<1 || wt->len<1) {
|
|
|
|
rWriteMask(addr>>1,0,mask);
|
|
|
|
} else {
|
2023-07-21 20:54:35 -04:00
|
|
|
int data=wt->data[i]*15/wt->max;
|
2022-04-12 01:17:34 -04:00
|
|
|
if (data<0) data=0;
|
|
|
|
if (data>15) data=15;
|
|
|
|
rWriteMask(addr>>1,(addr&1)?(data<<4):(data&0xf),mask);
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::updateWaveCh(int ch) {
|
|
|
|
if (ch<=chanMax) {
|
2023-07-20 17:50:19 -04:00
|
|
|
//logV("updateWave with pos %d and len %d",chan[ch].wavePos,chan[ch].waveLen);
|
2022-04-12 01:17:34 -04:00
|
|
|
updateWave(ch,-1,chan[ch].wavePos,chan[ch].waveLen);
|
2022-03-28 11:31:17 -04:00
|
|
|
if (chan[ch].active && !isMuted[ch]) {
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[ch].volumeChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-15 16:01:11 -04:00
|
|
|
void DivPlatformN163::tick(bool sysTick) {
|
2022-03-22 12:48:45 -04:00
|
|
|
for (int i=0; i<=chanMax; i++) {
|
|
|
|
chan[i].std.next();
|
2022-04-10 01:01:55 -04:00
|
|
|
if (chan[i].std.vol.had) {
|
|
|
|
chan[i].outVol=(MIN(15,chan[i].std.vol.val)*(chan[i].vol&15))/15;
|
2022-03-22 12:48:45 -04:00
|
|
|
if (chan[i].outVol<0) chan[i].outVol=0;
|
|
|
|
if (chan[i].outVol>15) chan[i].outVol=15;
|
|
|
|
if (chan[i].resVol!=chan[i].outVol) {
|
|
|
|
chan[i].resVol=chan[i].outVol;
|
|
|
|
if (!isMuted[i]) {
|
|
|
|
chan[i].volumeChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-17 01:21:08 -05:00
|
|
|
if (NEW_ARP_STRAT) {
|
|
|
|
chan[i].handleArp();
|
|
|
|
} else if (chan[i].std.arp.had) {
|
2022-03-22 12:48:45 -04:00
|
|
|
if (!chan[i].inPorta) {
|
2022-08-22 16:59:45 -04:00
|
|
|
chan[i].baseFreq=NOTE_FREQUENCY(parent->calcArp(chan[i].note,chan[i].std.arp.val));
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-04-10 01:01:55 -04:00
|
|
|
if (chan[i].std.duty.had) {
|
2023-07-19 01:16:44 -04:00
|
|
|
if (chan[i].curWavePos!=chan[i].std.duty.val) {
|
|
|
|
chan[i].curWavePos=chan[i].std.duty.val;
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].waveChanged=true;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 01:01:55 -04:00
|
|
|
if (chan[i].std.wave.had) {
|
2023-07-03 23:49:59 -04:00
|
|
|
if (chan[i].wave!=chan[i].std.wave.val || chan[i].ws.activeChanged()) {
|
2022-04-10 01:01:55 -04:00
|
|
|
chan[i].wave=chan[i].std.wave.val;
|
2022-04-12 01:17:34 -04:00
|
|
|
chan[i].ws.changeWave1(chan[i].wave);
|
2023-07-20 19:23:58 -04:00
|
|
|
if (chan[i].waveMode) {
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].waveUpdated=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-16 02:39:40 -04:00
|
|
|
if (chan[i].std.pitch.had) {
|
2022-04-28 02:31:16 -04:00
|
|
|
if (chan[i].std.pitch.mode) {
|
|
|
|
chan[i].pitch2+=chan[i].std.pitch.val;
|
2022-05-22 23:47:40 -04:00
|
|
|
CLAMP_VAR(chan[i].pitch2,-32768,32767);
|
2022-04-28 02:31:16 -04:00
|
|
|
} else {
|
|
|
|
chan[i].pitch2=chan[i].std.pitch.val;
|
|
|
|
}
|
2022-04-16 02:39:40 -04:00
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-04-10 01:01:55 -04:00
|
|
|
if (chan[i].std.ex1.had) {
|
2023-07-19 01:16:44 -04:00
|
|
|
if (chan[i].curWaveLen!=(chan[i].std.ex1.val&0xfc)) {
|
|
|
|
chan[i].curWaveLen=chan[i].std.ex1.val&0xfc;
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (chan[i].volumeChanged) {
|
2022-03-28 11:31:17 -04:00
|
|
|
if (chan[i].active && !isMuted[i]) {
|
2022-03-22 12:48:45 -04:00
|
|
|
chWriteMask(i,0x7,chan[i].resVol&0xf,0xf);
|
2022-03-28 11:31:17 -04:00
|
|
|
} else {
|
|
|
|
chWriteMask(i,0x7,0,0xf);
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
chan[i].volumeChanged=false;
|
|
|
|
}
|
|
|
|
if (chan[i].waveChanged) {
|
2023-07-19 01:16:44 -04:00
|
|
|
chWrite(i,0x6,chan[i].curWavePos);
|
2022-03-28 11:31:17 -04:00
|
|
|
if (chan[i].active) {
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].waveChanged=false;
|
|
|
|
}
|
2022-04-12 01:17:34 -04:00
|
|
|
if (chan[i].active) {
|
|
|
|
if (chan[i].ws.tick()) {
|
|
|
|
chan[i].waveUpdated=true;
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
if (chan[i].waveUpdated) {
|
|
|
|
updateWaveCh(i);
|
2022-03-28 11:31:17 -04:00
|
|
|
if (chan[i].active) {
|
|
|
|
if (!chan[i].keyOff) chan[i].keyOn=true;
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].waveUpdated=false;
|
|
|
|
}
|
|
|
|
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
2022-05-15 12:28:59 -04:00
|
|
|
// TODO: what is this mess?
|
2022-12-17 02:07:24 -05: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,2,chan[i].pitch2,chipClock,CHIP_FREQBASE);
|
2023-07-23 16:57:25 -04:00
|
|
|
if (lenCompensate) {
|
|
|
|
chan[i].freq=(((chan[i].freq*chan[i].curWaveLen)*(chanMax+1))/256);
|
|
|
|
} else {
|
|
|
|
chan[i].freq*=(chanMax+1);
|
|
|
|
chan[i].freq>>=3;
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
if (chan[i].freq<0) chan[i].freq=0;
|
|
|
|
if (chan[i].freq>0x3ffff) chan[i].freq=0x3ffff;
|
|
|
|
if (chan[i].keyOn) {
|
|
|
|
}
|
|
|
|
if (chan[i].keyOff && !isMuted[i]) {
|
2022-03-28 11:31:17 -04:00
|
|
|
chWriteMask(i,0x7,0,0xf);
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
chWrite(i,0x0,chan[i].freq&0xff);
|
|
|
|
chWrite(i,0x2,chan[i].freq>>8);
|
2023-07-19 01:16:44 -04:00
|
|
|
chWrite(i,0x4,((256-chan[i].curWaveLen)&0xfc)|((chan[i].freq>>16)&3));
|
2022-03-22 12:48:45 -04:00
|
|
|
if (chan[i].keyOn) chan[i].keyOn=false;
|
|
|
|
if (chan[i].keyOff) chan[i].keyOff=false;
|
|
|
|
chan[i].freqChanged=false;
|
|
|
|
}
|
|
|
|
}
|
2024-03-14 18:58:55 -04:00
|
|
|
|
|
|
|
// update memory composition positions
|
|
|
|
for (int i=0; i<=chanMax; i++) {
|
|
|
|
memCompo.entries[i].begin=chan[i].wavePos>>1;
|
|
|
|
memCompo.entries[i].end=(chan[i].wavePos+chan[i].waveLen)>>1;
|
|
|
|
memCompo.entries[i+8].begin=chan[i].curWavePos>>1;
|
|
|
|
memCompo.entries[i+8].end=(chan[i].curWavePos+chan[i].curWaveLen)>>1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update register pool
|
|
|
|
for (int i=0; i<128; i++) {
|
|
|
|
regPool[i]=n163.reg(i);
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformN163::dispatch(DivCommand c) {
|
|
|
|
switch (c.cmd) {
|
|
|
|
case DIV_CMD_NOTE_ON: {
|
2022-04-21 03:24:06 -04:00
|
|
|
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_N163);
|
2022-03-23 14:53:07 -04:00
|
|
|
if (chan[c.chan].insChanged) {
|
2023-07-20 19:23:58 -04:00
|
|
|
if (ins->n163.wave>=0) {
|
|
|
|
chan[c.chan].wave=ins->n163.wave;
|
|
|
|
}
|
2023-07-21 20:54:35 -04:00
|
|
|
chan[c.chan].wavePos=ins->n163.perChanPos?ins->n163.wavePosCh[c.chan&7]:ins->n163.wavePos;
|
|
|
|
chan[c.chan].waveLen=ins->n163.perChanPos?ins->n163.waveLenCh[c.chan&7]:ins->n163.waveLen;
|
2022-03-23 14:53:07 -04:00
|
|
|
chan[c.chan].waveMode=ins->n163.waveMode;
|
2023-07-19 01:16:44 -04:00
|
|
|
chan[c.chan].curWavePos=chan[c.chan].wavePos;
|
|
|
|
chan[c.chan].curWaveLen=chan[c.chan].waveLen;
|
2023-07-19 02:43:41 -04:00
|
|
|
chan[c.chan].ws.init(NULL,chan[c.chan].waveLen,15,true);
|
2023-07-20 19:23:58 -04:00
|
|
|
if (chan[c.chan].wave<0) {
|
|
|
|
chan[c.chan].wave=0;
|
|
|
|
}
|
2023-03-16 05:21:52 -04:00
|
|
|
chan[c.chan].ws.changeWave1(chan[c.chan].wave);
|
2022-03-23 14:53:07 -04:00
|
|
|
chan[c.chan].waveChanged=true;
|
2023-07-20 19:23:58 -04:00
|
|
|
if (chan[c.chan].waveMode) {
|
2022-03-23 14:53:07 -04:00
|
|
|
chan[c.chan].waveUpdated=true;
|
|
|
|
}
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
if (c.value!=DIV_NOTE_NULL) {
|
|
|
|
chan[c.chan].baseFreq=NOTE_FREQUENCY(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].resVol=chan[c.chan].vol;
|
|
|
|
if (!isMuted[c.chan]) {
|
|
|
|
chan[c.chan].volumeChanged=true;
|
|
|
|
}
|
2022-04-28 02:31:16 -04:00
|
|
|
chan[c.chan].macroInit(ins);
|
2022-04-12 01:17:34 -04:00
|
|
|
chan[c.chan].ws.init(ins,chan[c.chan].waveLen,15,chan[c.chan].insChanged);
|
2023-03-16 06:52:29 -04:00
|
|
|
chan[c.chan].insChanged=false;
|
2022-03-22 12:48:45 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case DIV_CMD_NOTE_OFF:
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].keyOff=true;
|
|
|
|
chan[c.chan].keyOn=false;
|
2023-07-20 19:23:58 -04:00
|
|
|
chan[c.chan].macroInit(NULL);
|
2022-03-22 12:48:45 -04:00
|
|
|
break;
|
|
|
|
case DIV_CMD_NOTE_OFF_ENV:
|
|
|
|
chan[c.chan].active=false;
|
|
|
|
chan[c.chan].keyOff=true;
|
|
|
|
chan[c.chan].keyOn=false;
|
|
|
|
chan[c.chan].std.release();
|
|
|
|
break;
|
|
|
|
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].insChanged=true;
|
|
|
|
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 01:01:55 -04:00
|
|
|
if (!chan[c.chan].std.vol.has) {
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].outVol=c.value;
|
|
|
|
chan[c.chan].resVol=chan[c.chan].outVol;
|
2022-03-29 19:28:38 -04:00
|
|
|
} else {
|
|
|
|
chan[c.chan].resVol=chan[c.chan].vol;
|
|
|
|
}
|
|
|
|
if (!isMuted[c.chan]) {
|
|
|
|
chan[c.chan].volumeChanged=true;
|
2022-03-22 12:48:45 -04: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: {
|
2024-03-19 13:50:44 -04:00
|
|
|
double destFreqD=NOTE_FREQUENCY(c.value2);
|
|
|
|
if (destFreqD>2000000000.0) destFreqD=2000000000.0;
|
|
|
|
int destFreq=destFreqD;
|
2022-03-22 12:48:45 -04:00
|
|
|
bool return2=false;
|
|
|
|
if (destFreq>chan[c.chan].baseFreq) {
|
2023-07-23 16:57:25 -04:00
|
|
|
chan[c.chan].baseFreq+=c.value*((parent->song.linearPitch==2)?1:16);
|
2022-03-22 12:48:45 -04:00
|
|
|
if (chan[c.chan].baseFreq>=destFreq) {
|
|
|
|
chan[c.chan].baseFreq=destFreq;
|
|
|
|
return2=true;
|
|
|
|
}
|
|
|
|
} else {
|
2023-07-23 16:57:25 -04:00
|
|
|
chan[c.chan].baseFreq-=c.value*((parent->song.linearPitch==2)?1:16);
|
2022-03-22 12:48:45 -04:00
|
|
|
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_WAVE:
|
|
|
|
chan[c.chan].wave=c.value;
|
2024-03-16 04:48:13 -04:00
|
|
|
chan[c.chan].ws.changeWave1(chan[c.chan].wave);
|
2023-07-20 19:23:58 -04:00
|
|
|
if (chan[c.chan].waveMode) {
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].waveUpdated=true;
|
|
|
|
}
|
|
|
|
chan[c.chan].keyOn=true;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_N163_WAVE_POSITION:
|
2023-07-19 01:16:44 -04:00
|
|
|
chan[c.chan].curWavePos=c.value;
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].waveChanged=true;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_N163_WAVE_LENGTH:
|
2023-07-19 01:16:44 -04:00
|
|
|
chan[c.chan].curWaveLen=c.value&0xfc;
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].freqChanged=true;
|
|
|
|
break;
|
2023-07-21 20:54:35 -04:00
|
|
|
case DIV_CMD_N163_WAVE_LOADPOS:
|
|
|
|
chan[c.chan].wavePos=c.value;
|
|
|
|
if (chan[c.chan].waveMode) {
|
|
|
|
chan[c.chan].waveUpdated=true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_N163_WAVE_LOADLEN:
|
|
|
|
chan[c.chan].waveLen=c.value&0xfc;
|
|
|
|
if (chan[c.chan].waveMode) {
|
|
|
|
chan[c.chan].waveUpdated=true;
|
|
|
|
}
|
|
|
|
break;
|
2022-03-22 12:48:45 -04:00
|
|
|
case DIV_CMD_N163_GLOBAL_WAVE_LOAD:
|
|
|
|
loadWave=c.value;
|
2023-07-21 20:54:35 -04:00
|
|
|
if (loadWave>=0 && loadWave<parent->song.waveLen) {
|
|
|
|
updateWave(-1,loadWave,loadPos,-1);
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
break;
|
|
|
|
case DIV_CMD_N163_GLOBAL_WAVE_LOADPOS:
|
|
|
|
loadPos=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_N163_CHANNEL_LIMIT:
|
|
|
|
if (chanMax!=(c.value&0x7)) {
|
|
|
|
chanMax=c.value&0x7;
|
|
|
|
rWriteMask(0x7f,chanMax<<4,0x70);
|
|
|
|
forceIns();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DIV_CMD_LEGATO:
|
2022-12-17 02:07:24 -05:00
|
|
|
chan[c.chan].baseFreq=NOTE_FREQUENCY(c.value+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0)));
|
2022-03-22 12:48:45 -04: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) {
|
|
|
|
if (parent->song.resetMacroOnPorta) {
|
2022-04-28 02:31:16 -04:00
|
|
|
chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_N163));
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].keyOn=true;
|
|
|
|
}
|
|
|
|
}
|
2022-12-17 02:10:20 -05: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);
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[c.chan].inPorta=c.value;
|
|
|
|
break;
|
|
|
|
case DIV_CMD_GET_VOLMAX:
|
|
|
|
return 15;
|
|
|
|
break;
|
2022-12-17 00:09:56 -05: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;
|
2024-01-17 14:48:47 -05:00
|
|
|
case DIV_CMD_MACRO_RESTART:
|
|
|
|
chan[c.chan].std.restart(c.value);
|
2024-01-17 07:28:29 -05:00
|
|
|
break;
|
2022-03-22 12:48:45 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::muteChannel(int ch, bool mute) {
|
|
|
|
isMuted[ch]=mute;
|
|
|
|
chan[ch].volumeChanged=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::forceIns() {
|
|
|
|
for (int i=0; i<=chanMax; i++) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
if (chan[i].active) {
|
|
|
|
chan[i].keyOn=true;
|
|
|
|
chan[i].freqChanged=true;
|
|
|
|
chan[i].volumeChanged=true;
|
|
|
|
chan[i].waveChanged=true;
|
|
|
|
}
|
|
|
|
}
|
2024-03-14 18:58:55 -04:00
|
|
|
memCompo.entries[16].begin=120-chanMax*8;
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::notifyWaveChange(int wave) {
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
if (chan[i].wave==wave) {
|
2023-07-20 19:23:58 -04:00
|
|
|
if (chan[i].waveMode) {
|
2022-04-12 01:17:34 -04:00
|
|
|
chan[i].ws.changeWave1(wave);
|
2022-03-22 12:48:45 -04:00
|
|
|
chan[i].waveUpdated=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::notifyInsChange(int ins) {
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
if (chan[i].ins==ins) {
|
|
|
|
chan[i].insChanged=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::notifyInsDeletion(void* ins) {
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
chan[i].std.notifyInsDeletion((DivInstrument*)ins);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* DivPlatformN163::getChanState(int ch) {
|
|
|
|
return &chan[ch];
|
|
|
|
}
|
|
|
|
|
2022-06-05 19:17:00 -04:00
|
|
|
DivMacroInt* DivPlatformN163::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 03:40:03 -04:00
|
|
|
DivDispatchOscBuffer* DivPlatformN163::getOscBuffer(int ch) {
|
|
|
|
return oscBuf[ch];
|
|
|
|
}
|
|
|
|
|
2022-03-22 12:48:45 -04:00
|
|
|
unsigned char* DivPlatformN163::getRegisterPool() {
|
|
|
|
return regPool;
|
|
|
|
}
|
|
|
|
|
|
|
|
int DivPlatformN163::getRegisterPoolSize() {
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::reset() {
|
|
|
|
while (!writes.empty()) writes.pop();
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
chan[i]=DivPlatformN163::Channel();
|
2022-04-15 06:37:23 -04:00
|
|
|
chan[i].std.setEngine(parent);
|
2022-04-12 01:17:34 -04:00
|
|
|
chan[i].ws.setEngine(parent);
|
|
|
|
chan[i].ws.init(NULL,32,15,false);
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
2022-03-28 15:56:35 -04:00
|
|
|
n163.reset();
|
2022-03-22 12:48:45 -04:00
|
|
|
memset(regPool,0,128);
|
|
|
|
|
2022-03-28 15:56:35 -04:00
|
|
|
n163.set_disable(false);
|
2022-04-10 07:22:49 -04:00
|
|
|
n163.set_multiplex(multiplex);
|
2022-03-28 15:56:35 -04:00
|
|
|
chanMax=initChanMax;
|
2022-03-22 12:48:45 -04:00
|
|
|
loadWave=-1;
|
|
|
|
loadPos=0;
|
2022-03-28 15:56:35 -04:00
|
|
|
rWrite(0x7f,initChanMax<<4);
|
2024-03-14 18:58:55 -04:00
|
|
|
|
|
|
|
memCompo.entries[16].begin=120-chanMax*8;
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::poke(unsigned int addr, unsigned short val) {
|
|
|
|
rWrite(addr,val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::poke(std::vector<DivRegWrite>& wlist) {
|
|
|
|
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val);
|
|
|
|
}
|
|
|
|
|
2024-03-14 18:58:55 -04:00
|
|
|
const DivMemoryComposition* DivPlatformN163::getMemCompo(int index) {
|
|
|
|
if (index!=0) return NULL;
|
|
|
|
return &memCompo;
|
|
|
|
}
|
|
|
|
|
2022-09-29 21:13:40 -04:00
|
|
|
void DivPlatformN163::setFlags(const DivConfig& flags) {
|
|
|
|
switch (flags.getInt("clockSel",0)) {
|
|
|
|
case 1: // PAL
|
2022-12-04 02:04:42 -05:00
|
|
|
chipClock=COLOR_PAL*3.0/8.0;
|
2022-03-22 12:48:45 -04:00
|
|
|
break;
|
2022-09-29 21:13:40 -04:00
|
|
|
case 2: // Dendy
|
2022-12-04 02:04:42 -05:00
|
|
|
chipClock=COLOR_PAL*2.0/5.0;
|
2022-03-22 12:48:45 -04:00
|
|
|
break;
|
2022-09-29 21:13:40 -04:00
|
|
|
default: // NTSC
|
2022-12-04 02:04:42 -05:00
|
|
|
chipClock=COLOR_NTSC/2.0;
|
2022-09-29 21:13:40 -04:00
|
|
|
break;
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
2022-12-04 02:04:42 -05:00
|
|
|
CHECK_CUSTOM_CLOCK;
|
2022-09-29 21:13:40 -04:00
|
|
|
initChanMax=chanMax=flags.getInt("channels",0)&7;
|
|
|
|
multiplex=!flags.getBool("multiplex",false); // not accurate in real hardware
|
2022-12-04 02:04:42 -05:00
|
|
|
rate=chipClock;
|
2022-03-22 12:48:45 -04:00
|
|
|
rate/=15;
|
2022-04-10 07:22:49 -04:00
|
|
|
n163.set_multiplex(multiplex);
|
2022-03-28 15:56:35 -04:00
|
|
|
rWrite(0x7f,initChanMax<<4);
|
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 03:40:03 -04:00
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
oscBuf[i]->rate=rate/(initChanMax+1);
|
|
|
|
}
|
2022-09-08 04:01:22 -04:00
|
|
|
|
2023-07-23 16:57:25 -04:00
|
|
|
lenCompensate=flags.getBool("lenCompensate",false);
|
|
|
|
|
2022-09-08 04:01:22 -04:00
|
|
|
// needed to make sure changing channel count won't trigger glitches
|
|
|
|
reset();
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
2022-09-29 21:13:40 -04:00
|
|
|
int DivPlatformN163::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) {
|
2022-03-22 12:48:45 -04:00
|
|
|
parent=p;
|
|
|
|
dumpWrites=false;
|
|
|
|
skipRegisterWrites=false;
|
|
|
|
for (int i=0; i<8; 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 03:40:03 -04:00
|
|
|
oscBuf[i]=new DivDispatchOscBuffer;
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
2024-03-14 18:58:55 -04:00
|
|
|
|
|
|
|
memCompo.used=0;
|
|
|
|
memCompo.capacity=128;
|
|
|
|
memCompo.memory=regPool;
|
|
|
|
memCompo.waveformView=DIV_MEMORY_WAVE_4BIT;
|
|
|
|
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_N163_LOAD,fmt::sprintf("Channel %d (load)",i),-1,0,0));
|
|
|
|
}
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_N163_PLAY,fmt::sprintf("Channel %d (play)",i),-1,0,0));
|
|
|
|
}
|
|
|
|
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_RESERVED,"Registers",-1,127,128));
|
|
|
|
|
2022-03-22 12:48:45 -04:00
|
|
|
setFlags(flags);
|
|
|
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
return 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DivPlatformN163::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 03:40:03 -04:00
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
delete oscBuf[i];
|
|
|
|
}
|
2022-03-22 12:48:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
DivPlatformN163::~DivPlatformN163() {
|
|
|
|
}
|