| 1 |
/** |
| 2 |
* Furnace Tracker - multi-system chiptune tracker |
| 3 |
* Copyright (C) 2021-2025 tildearrow and contributors |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License along |
| 16 |
* with this program; if not, write to the Free Software Foundation, Inc., |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "swan_before.h" |
| 21 |
#include "../engine.h" |
| 22 |
#include "furIcons.h" |
| 23 |
#include "IconsFontAwesome4.h" |
| 24 |
#include <math.h> |
| 25 |
|
| 26 |
#define rWrite(a,v) if (!skipRegisterWrites) {writes.push(QueuedWrite(a,v)); if (dumpWrites) {addWrite(a,v);}} |
| 27 |
#define postWrite(a,v) postDACWrites.push(DivRegWrite(a,v)); |
| 28 |
|
| 29 |
#define CHIP_DIVIDER 32 |
| 30 |
|
| 31 |
const char* regCheatSheetWS[]={ |
| 32 |
"CH1_Pitch", "00", |
| 33 |
"CH2_Pitch", "02", |
| 34 |
"CH3_Pitch", "04", |
| 35 |
"CH4_Pitch", "06", |
| 36 |
"CH1_Vol", "08", |
| 37 |
"CH2_Vol", "09", |
| 38 |
"CH3_Vol", "0A", |
| 39 |
"CH4_Vol", "0B", |
| 40 |
"Sweep_Value", "0C", |
| 41 |
"Sweep_Time", "0D", |
| 42 |
"Noise", "0E", |
| 43 |
"Wave_Base", "0F", |
| 44 |
"Ctrl", "10", |
| 45 |
"Output", "11", |
| 46 |
"Random", "12", |
| 47 |
"Voice_Ctrl", "14", |
| 48 |
"Wave_Mem", "40", |
| 49 |
NULL |
| 50 |
}; |
| 51 |
|
| 52 |
const char** DivPlatformSwan::getRegisterSheet() { |
| 53 |
return regCheatSheetWS; |
| 54 |
} |
| 55 |
|
| 56 |
void DivPlatformSwan::acquireDirect(blip_buffer_t** bb, size_t len) { |
| 57 |
for (int i=0; i<4; i++) { |
| 58 |
oscBuf[i]->begin(len); |
| 59 |
ws_mdfn->oscBuf[i]=oscBuf[i]; |
| 60 |
} |
| 61 |
|
| 62 |
ws_mdfn->sbuf[0]=bb[0]; |
| 63 |
ws_mdfn->sbuf[1]=bb[1]; |
| 64 |
|
| 65 |
for (size_t h=0; h<len; h++) { |
| 66 |
ws_mdfn->v30mz_timestamp=h; |
| 67 |
// heuristic |
| 68 |
int pcmAdvance=1; |
| 69 |
if (writes.empty()) { |
| 70 |
if (!pcm || dacSample==-1) { |
| 71 |
break; |
| 72 |
} else { |
| 73 |
pcmAdvance=len-h; |
| 74 |
if (dacRate>0) { |
| 75 |
int remainTime=(rate-dacPeriod+dacRate-1)/dacRate; |
| 76 |
if (remainTime<pcmAdvance) pcmAdvance=remainTime; |
| 77 |
if (remainTime<1) pcmAdvance=1; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
|
| 82 |
// PCM part |
| 83 |
if (pcm && dacSample!=-1) { |
| 84 |
dacPeriod+=dacRate*pcmAdvance; |
| 85 |
while (dacPeriod>=rate) { |
| 86 |
DivSample* s=parent->getSample(dacSample); |
| 87 |
if (s->samples<=0 || dacPos>=s->samples) { |
| 88 |
dacSample=-1; |
| 89 |
dacPeriod=0; |
| 90 |
break; |
| 91 |
} |
| 92 |
rWrite(0x09,(unsigned char)s->data8[dacPos++]+0x80); |
| 93 |
if (s->isLoopable() && dacPos>=(unsigned int)s->loopEnd) { |
| 94 |
dacPos=s->loopStart; |
| 95 |
} else if (dacPos>=s->samples) { |
| 96 |
dacSample=-1; |
| 97 |
} |
| 98 |
dacPeriod-=rate; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
h+=pcmAdvance-1; |
| 103 |
|
| 104 |
// the rest |
| 105 |
while (!writes.empty()) { |
| 106 |
QueuedWrite w=writes.front(); |
| 107 |
regPool[w.addr]=w.val; |
| 108 |
if (w.addr<0x40) { |
| 109 |
ws_mdfn->SoundWrite(w.addr|0x80,w.val); |
| 110 |
} else { |
| 111 |
ws_mdfn->SoundCheckRAMWrite(w.addr&0x3f); |
| 112 |
ws_mdfn->RAMWrite(w.addr&0x3f,w.val); |
| 113 |
} |
| 114 |
writes.pop(); |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
ws_mdfn->v30mz_timestamp=len; |
| 119 |
ws_mdfn->SoundUpdate(); |
| 120 |
ws_mdfn->SoundFlush(NULL,0); |
| 121 |
|
| 122 |
for (int i=0; i<4; i++) { |
| 123 |
oscBuf[i]->end(len); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
void DivPlatformSwan::updateWave(int ch) { |
| 128 |
unsigned char addr=0x40+ch*16; |
| 129 |
for (int i=0; i<16; i++) { |
| 130 |
int nibble1=chan[ch].ws.output[i<<1]; |
| 131 |
int nibble2=chan[ch].ws.output[1+(i<<1)]; |
| 132 |
rWrite(addr+i,nibble1|(nibble2<<4)); |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
void DivPlatformSwan::calcAndWriteOutVol(int ch, int env) { |
| 137 |
int vl=chan[ch].vol*((chan[ch].pan>>4)&0x0f)*env/225; |
| 138 |
int vr=chan[ch].vol*(chan[ch].pan&0x0f)*env/225; |
| 139 |
if (ch==1&&pcm) { |
| 140 |
vl=(vl>0)?((vl>7)?3:2):0; |
| 141 |
vr=(vr>0)?((vr>7)?3:2):0; |
| 142 |
chan[1].outVol=vr|(vl<<2); |
| 143 |
} else { |
| 144 |
chan[ch].outVol=vr|(vl<<4); |
| 145 |
} |
| 146 |
writeOutVol(ch); |
| 147 |
} |
| 148 |
|
| 149 |
void DivPlatformSwan::writeOutVol(int ch) { |
| 150 |
unsigned char val=isMuted[ch]?0:chan[ch].outVol; |
| 151 |
if (ch==1&&pcm) { |
| 152 |
rWrite(0x14,val) |
| 153 |
} else { |
| 154 |
rWrite(0x08+ch,val); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
void DivPlatformSwan::tick(bool sysTick) { |
| 159 |
unsigned char sndCtrl=(pcm?0x20:0)|(sweep?0x40:0)|((noise>0)?0x80:0); |
| 160 |
for (int i=0; i<4; i++) { |
| 161 |
chan[i].std.next(); |
| 162 |
if (chan[i].std.vol.had) { |
| 163 |
int env=chan[i].std.vol.val; |
| 164 |
if(parent->getIns(chan[i].ins,DIV_INS_SWAN)->type==DIV_INS_AMIGA) { |
| 165 |
env=MIN(env/4,15); |
| 166 |
} |
| 167 |
calcAndWriteOutVol(i,env); |
| 168 |
} |
| 169 |
if (NEW_ARP_STRAT) { |
| 170 |
chan[i].handleArp(); |
| 171 |
} else if (chan[i].std.arp.had) { |
| 172 |
if (!chan[i].inPorta) { |
| 173 |
chan[i].baseFreq=NOTE_PERIODIC(parent->calcArp(chan[i].note,chan[i].std.arp.val)); |
| 174 |
} |
| 175 |
chan[i].freqChanged=true; |
| 176 |
} |
| 177 |
if (chan[i].std.wave.had && !(i==1 && pcm)) { |
| 178 |
if (chan[i].wave!=chan[i].std.wave.val || chan[i].ws.activeChanged()) { |
| 179 |
chan[i].wave=chan[i].std.wave.val; |
| 180 |
chan[i].ws.changeWave1(chan[i].wave); |
| 181 |
} |
| 182 |
} |
| 183 |
if (chan[i].std.panL.had) { |
| 184 |
chan[i].pan&=0x0f; |
| 185 |
chan[i].pan|=(chan[i].std.panL.val&15)<<4; |
| 186 |
} |
| 187 |
if (chan[i].std.panR.had) { |
| 188 |
chan[i].pan&=0xf0; |
| 189 |
chan[i].pan|=chan[i].std.panR.val&15; |
| 190 |
} |
| 191 |
if (chan[i].std.panL.had || chan[i].std.panR.had) { |
| 192 |
calcAndWriteOutVol(i,chan[i].std.vol.will?chan[i].std.vol.val:15); |
| 193 |
} |
| 194 |
if (chan[i].std.pitch.had) { |
| 195 |
if (chan[i].std.pitch.mode) { |
| 196 |
chan[i].pitch2+=chan[i].std.pitch.val; |
| 197 |
CLAMP_VAR(chan[i].pitch2,-32768,32767); |
| 198 |
} else { |
| 199 |
chan[i].pitch2=chan[i].std.pitch.val; |
| 200 |
} |
| 201 |
chan[i].freqChanged=true; |
| 202 |
} |
| 203 |
if (chan[i].active) { |
| 204 |
sndCtrl|=(1<<i); |
| 205 |
if (chan[i].ws.tick()) { |
| 206 |
updateWave(i); |
| 207 |
} |
| 208 |
} |
| 209 |
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { |
| 210 |
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); |
| 211 |
if (i==1 && pcm && furnaceDac) { |
| 212 |
double off=1.0; |
| 213 |
if (dacSample>=0 && dacSample<parent->song.sampleLen) { |
| 214 |
DivSample* s=parent->getSample(dacSample); |
| 215 |
if (s->centerRate<1) { |
| 216 |
off=1.0; |
| 217 |
} else { |
| 218 |
off=parent->getCenterRate()/(double)s->centerRate; |
| 219 |
} |
| 220 |
} |
| 221 |
dacRate=((double)chipClock/2)/MAX(1,off*chan[i].freq); |
| 222 |
if (dumpWrites) postWrite(0xffff0001,dacRate); |
| 223 |
} |
| 224 |
if (chan[i].freq>2048) chan[i].freq=2048; |
| 225 |
if (chan[i].freq<1) chan[i].freq=1; |
| 226 |
int rVal=2048-chan[i].freq; |
| 227 |
rWrite(i*2,rVal&0xff); |
| 228 |
rWrite(i*2+1,rVal>>8); |
| 229 |
if (chan[i].keyOn) { |
| 230 |
if (!chan[i].std.vol.will) { |
| 231 |
calcAndWriteOutVol(i,15); |
| 232 |
} |
| 233 |
chan[i].keyOn=false; |
| 234 |
} |
| 235 |
if (chan[i].keyOff) { |
| 236 |
chan[i].keyOff=false; |
| 237 |
} |
| 238 |
chan[i].freqChanged=false; |
| 239 |
} |
| 240 |
} |
| 241 |
if (chan[3].std.duty.had) { |
| 242 |
if (noise!=chan[3].std.duty.val) { |
| 243 |
noise=chan[3].std.duty.val; |
| 244 |
if (noise>0) { |
| 245 |
rWrite(0x0e,((noise-1)&0x07)|0x18); |
| 246 |
sndCtrl|=0x80; |
| 247 |
} else { |
| 248 |
sndCtrl&=~0x80; |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
if (chan[3].std.phaseReset.had) { |
| 253 |
if (noise>0) { |
| 254 |
rWrite(0x0e,((noise-1)&0x07)|0x18); |
| 255 |
sndCtrl|=0x80; |
| 256 |
} else { |
| 257 |
sndCtrl&=~0x80; |
| 258 |
} |
| 259 |
} |
| 260 |
unsigned char origSndCtrl=sndCtrl; |
| 261 |
bool phaseResetHappens=false; |
| 262 |
for (int i=0; i<4; i++) { |
| 263 |
if (chan[i].std.phaseReset.had) { |
| 264 |
phaseResetHappens=true; |
| 265 |
sndCtrl&=~(1<<i); |
| 266 |
} |
| 267 |
} |
| 268 |
if (phaseResetHappens) { |
| 269 |
rWrite(0x10,sndCtrl); |
| 270 |
sndCtrl=origSndCtrl; |
| 271 |
} |
| 272 |
rWrite(0x10,sndCtrl); |
| 273 |
|
| 274 |
while (!postDACWrites.empty()) { |
| 275 |
const DivRegWrite& w=postDACWrites.back(); |
| 276 |
if (dumpWrites) addWrite(w.addr,w.val); |
| 277 |
postDACWrites.pop(); |
| 278 |
} |
| 279 |
} |
| 280 |
|
| 281 |
int DivPlatformSwan::dispatch(DivCommand c) { |
| 282 |
switch (c.cmd) { |
| 283 |
case DIV_CMD_NOTE_ON: { |
| 284 |
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_SWAN); |
| 285 |
if (c.chan==1) { |
| 286 |
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { |
| 287 |
pcm=true; |
| 288 |
} else if (furnaceDac) { |
| 289 |
pcm=false; |
| 290 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 291 |
chan[c.chan].sampleNoteDelta=0; |
| 292 |
} |
| 293 |
if (pcm) { |
| 294 |
if (skipRegisterWrites) break; |
| 295 |
if (setPos) { |
| 296 |
setPos=false; |
| 297 |
} else { |
| 298 |
dacPos=0; |
| 299 |
} |
| 300 |
dacPeriod=0; |
| 301 |
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { |
| 302 |
if (c.value!=DIV_NOTE_NULL) { |
| 303 |
dacSample=ins->amiga.getSample(c.value); |
| 304 |
chan[c.chan].sampleNote=c.value; |
| 305 |
c.value=ins->amiga.getFreq(c.value); |
| 306 |
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; |
| 307 |
} else if (chan[c.chan].sampleNote!=DIV_NOTE_NULL) { |
| 308 |
dacSample=ins->amiga.getSample(chan[c.chan].sampleNote); |
| 309 |
c.value=ins->amiga.getFreq(chan[c.chan].sampleNote); |
| 310 |
} |
| 311 |
if (dacSample<0 || dacSample>=parent->song.sampleLen) { |
| 312 |
dacSample=-1; |
| 313 |
if (dumpWrites) postWrite(0xffff0002,0); |
| 314 |
break; |
| 315 |
} else { |
| 316 |
if (dumpWrites) { |
| 317 |
postWrite(0xffff0000,dacSample); |
| 318 |
} |
| 319 |
} |
| 320 |
if (c.value!=DIV_NOTE_NULL) { |
| 321 |
chan[1].baseFreq=NOTE_PERIODIC(c.value); |
| 322 |
chan[1].freqChanged=true; |
| 323 |
chan[1].note=c.value; |
| 324 |
} |
| 325 |
chan[1].active=true; |
| 326 |
chan[1].keyOn=true; |
| 327 |
chan[1].macroInit(ins); |
| 328 |
furnaceDac=true; |
| 329 |
} else { |
| 330 |
if (c.value!=DIV_NOTE_NULL) { |
| 331 |
chan[1].note=c.value; |
| 332 |
} |
| 333 |
dacSample=12*sampleBank+chan[1].note%12; |
| 334 |
if (dacSample>=parent->song.sampleLen) { |
| 335 |
dacSample=-1; |
| 336 |
if (dumpWrites) postWrite(0xffff0002,0); |
| 337 |
break; |
| 338 |
} else { |
| 339 |
if (dumpWrites) postWrite(0xffff0000,dacSample); |
| 340 |
} |
| 341 |
dacRate=parent->getSample(dacSample)->rate; |
| 342 |
if (dumpWrites) { |
| 343 |
postWrite(0xffff0001,dacRate); |
| 344 |
} |
| 345 |
chan[1].active=true; |
| 346 |
chan[1].keyOn=true; |
| 347 |
furnaceDac=false; |
| 348 |
} |
| 349 |
break; |
| 350 |
} |
| 351 |
} |
| 352 |
if (c.value!=DIV_NOTE_NULL) { |
| 353 |
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); |
| 354 |
chan[c.chan].freqChanged=true; |
| 355 |
chan[c.chan].note=c.value; |
| 356 |
} |
| 357 |
chan[c.chan].active=true; |
| 358 |
chan[c.chan].keyOn=true; |
| 359 |
chan[c.chan].macroInit(ins); |
| 360 |
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { |
| 361 |
chan[c.chan].outVol=chan[c.chan].vol; |
| 362 |
} |
| 363 |
if (chan[c.chan].wave<0) { |
| 364 |
chan[c.chan].wave=0; |
| 365 |
chan[c.chan].ws.changeWave1(chan[c.chan].wave); |
| 366 |
} |
| 367 |
chan[c.chan].ws.init(ins,32,15,chan[c.chan].insChanged); |
| 368 |
chan[c.chan].insChanged=false; |
| 369 |
break; |
| 370 |
} |
| 371 |
case DIV_CMD_NOTE_OFF: |
| 372 |
if (c.chan==1&&pcm) { |
| 373 |
dacSample=-1; |
| 374 |
if (dumpWrites) postWrite(0xffff0002,0); |
| 375 |
pcm=false; |
| 376 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 377 |
chan[c.chan].sampleNoteDelta=0; |
| 378 |
} |
| 379 |
chan[c.chan].active=false; |
| 380 |
chan[c.chan].keyOff=true; |
| 381 |
chan[c.chan].macroInit(NULL); |
| 382 |
break; |
| 383 |
case DIV_CMD_NOTE_OFF_ENV: |
| 384 |
case DIV_CMD_ENV_RELEASE: |
| 385 |
chan[c.chan].std.release(); |
| 386 |
break; |
| 387 |
case DIV_CMD_INSTRUMENT: |
| 388 |
if (chan[c.chan].ins!=c.value || c.value2==1) { |
| 389 |
chan[c.chan].ins=c.value; |
| 390 |
chan[c.chan].insChanged=true; |
| 391 |
} |
| 392 |
break; |
| 393 |
case DIV_CMD_VOLUME: |
| 394 |
if (chan[c.chan].vol!=c.value) { |
| 395 |
chan[c.chan].vol=c.value; |
| 396 |
if (!chan[c.chan].std.vol.has) { |
| 397 |
calcAndWriteOutVol(c.chan,15); |
| 398 |
} |
| 399 |
} |
| 400 |
break; |
| 401 |
case DIV_CMD_GET_VOLUME: |
| 402 |
return chan[c.chan].vol; |
| 403 |
break; |
| 404 |
case DIV_CMD_PITCH: |
| 405 |
chan[c.chan].pitch=c.value; |
| 406 |
chan[c.chan].freqChanged=true; |
| 407 |
break; |
| 408 |
case DIV_CMD_WAVE: |
| 409 |
chan[c.chan].wave=c.value; |
| 410 |
chan[c.chan].ws.changeWave1(chan[c.chan].wave); |
| 411 |
chan[c.chan].keyOn=true; |
| 412 |
break; |
| 413 |
case DIV_CMD_WS_SWEEP_TIME: |
| 414 |
if (c.chan==2) { |
| 415 |
if (c.value==0) { |
| 416 |
sweep=false; |
| 417 |
} else { |
| 418 |
sweep=true; |
| 419 |
rWrite(0x0d,(c.value-1)&0xff); |
| 420 |
} |
| 421 |
} |
| 422 |
break; |
| 423 |
case DIV_CMD_WS_SWEEP_AMOUNT: |
| 424 |
if (c.chan==2) { |
| 425 |
rWrite(0x0c,c.value&0xff); |
| 426 |
} |
| 427 |
break; |
| 428 |
case DIV_CMD_NOTE_PORTA: { |
| 429 |
int destFreq=NOTE_PERIODIC(c.value2+chan[c.chan].sampleNoteDelta); |
| 430 |
bool return2=false; |
| 431 |
if (destFreq>chan[c.chan].baseFreq) { |
| 432 |
chan[c.chan].baseFreq+=c.value; |
| 433 |
if (chan[c.chan].baseFreq>=destFreq) { |
| 434 |
chan[c.chan].baseFreq=destFreq; |
| 435 |
return2=true; |
| 436 |
} |
| 437 |
} else { |
| 438 |
chan[c.chan].baseFreq-=c.value; |
| 439 |
if (chan[c.chan].baseFreq<=destFreq) { |
| 440 |
chan[c.chan].baseFreq=destFreq; |
| 441 |
return2=true; |
| 442 |
} |
| 443 |
} |
| 444 |
chan[c.chan].freqChanged=true; |
| 445 |
if (return2) { |
| 446 |
chan[c.chan].inPorta=false; |
| 447 |
return 2; |
| 448 |
} |
| 449 |
break; |
| 450 |
} |
| 451 |
case DIV_CMD_STD_NOISE_MODE: |
| 452 |
if (c.chan==3) { |
| 453 |
noise=c.value&0xff; |
| 454 |
if (noise>0) rWrite(0x0e,((noise-1)&0x07)|0x18); |
| 455 |
} |
| 456 |
break; |
| 457 |
case DIV_CMD_SAMPLE_MODE: |
| 458 |
if (c.chan==1) { |
| 459 |
pcm=c.value; |
| 460 |
if (!pcm) { |
| 461 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 462 |
chan[c.chan].sampleNoteDelta=0; |
| 463 |
} |
| 464 |
} |
| 465 |
break; |
| 466 |
case DIV_CMD_SAMPLE_BANK: |
| 467 |
sampleBank=c.value; |
| 468 |
if (sampleBank>(parent->song.sample.size()/12)) { |
| 469 |
sampleBank=parent->song.sample.size()/12; |
| 470 |
} |
| 471 |
break; |
| 472 |
case DIV_CMD_SAMPLE_POS: |
| 473 |
dacPos=c.value; |
| 474 |
setPos=true; |
| 475 |
break; |
| 476 |
case DIV_CMD_PANNING: { |
| 477 |
chan[c.chan].pan=(c.value&0xf0)|(c.value2>>4); |
| 478 |
calcAndWriteOutVol(c.chan,chan[c.chan].std.vol.will?chan[c.chan].std.vol.val:15); |
| 479 |
break; |
| 480 |
} |
| 481 |
case DIV_CMD_LEGATO: |
| 482 |
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+chan[c.chan].sampleNoteDelta+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0))); |
| 483 |
chan[c.chan].freqChanged=true; |
| 484 |
chan[c.chan].note=c.value; |
| 485 |
break; |
| 486 |
case DIV_CMD_PRE_PORTA: |
| 487 |
if (chan[c.chan].active && c.value2) { |
| 488 |
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_SWAN)); |
| 489 |
} |
| 490 |
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); |
| 491 |
chan[c.chan].inPorta=c.value; |
| 492 |
break; |
| 493 |
case DIV_CMD_GET_VOLMAX: |
| 494 |
return 15; |
| 495 |
break; |
| 496 |
case DIV_CMD_MACRO_OFF: |
| 497 |
chan[c.chan].std.mask(c.value,true); |
| 498 |
break; |
| 499 |
case DIV_CMD_MACRO_ON: |
| 500 |
chan[c.chan].std.mask(c.value,false); |
| 501 |
break; |
| 502 |
case DIV_CMD_MACRO_RESTART: |
| 503 |
chan[c.chan].std.restart(c.value); |
| 504 |
break; |
| 505 |
default: |
| 506 |
break; |
| 507 |
} |
| 508 |
return 1; |
| 509 |
} |
| 510 |
|
| 511 |
void DivPlatformSwan::muteChannel(int ch, bool mute) { |
| 512 |
isMuted[ch]=mute; |
| 513 |
writeOutVol(ch); |
| 514 |
} |
| 515 |
|
| 516 |
void DivPlatformSwan::forceIns() { |
| 517 |
noise=0; |
| 518 |
for (int i=0; i<4; i++) { |
| 519 |
chan[i].insChanged=true; |
| 520 |
chan[i].freqChanged=true; |
| 521 |
updateWave(i); |
| 522 |
writeOutVol(i); |
| 523 |
} |
| 524 |
} |
| 525 |
|
| 526 |
void* DivPlatformSwan::getChanState(int ch) { |
| 527 |
return &chan[ch]; |
| 528 |
} |
| 529 |
|
| 530 |
DivMacroInt* DivPlatformSwan::getChanMacroInt(int ch) { |
| 531 |
return &chan[ch].std; |
| 532 |
} |
| 533 |
|
| 534 |
unsigned short DivPlatformSwan::getPan(int ch) { |
| 535 |
return ((chan[ch].pan&0xf0)<<4)|(chan[ch].pan&15); |
| 536 |
} |
| 537 |
|
| 538 |
DivChannelModeHints DivPlatformSwan::getModeHints(int ch) { |
| 539 |
DivChannelModeHints ret; |
| 540 |
|
| 541 |
switch (ch) { |
| 542 |
case 1: // PCM |
| 543 |
ret.count=1; |
| 544 |
ret.hint[0]=ICON_FA_VOLUME_UP; |
| 545 |
ret.type[0]=pcm?4:0; |
| 546 |
break; |
| 547 |
case 2: // sweep |
| 548 |
ret.count=1; |
| 549 |
ret.hint[0]=ICON_FUR_SAW; |
| 550 |
ret.type[0]=sweep?2:0; |
| 551 |
break; |
| 552 |
case 3: // noise |
| 553 |
ret.count=1; |
| 554 |
ret.hint[0]=ICON_FUR_NOISE; |
| 555 |
ret.type[0]=noise?4:0; |
| 556 |
break; |
| 557 |
} |
| 558 |
|
| 559 |
return ret; |
| 560 |
} |
| 561 |
|
| 562 |
DivDispatchOscBuffer* DivPlatformSwan::getOscBuffer(int ch) { |
| 563 |
return oscBuf[ch]; |
| 564 |
} |
| 565 |
|
| 566 |
unsigned char* DivPlatformSwan::getRegisterPool() { |
| 567 |
// get Random from emulator |
| 568 |
regPool[0x12]=ws_mdfn->SoundRead(0x92); |
| 569 |
regPool[0x13]=ws_mdfn->SoundRead(0x93); |
| 570 |
return regPool; |
| 571 |
} |
| 572 |
|
| 573 |
int DivPlatformSwan::getRegisterPoolSize() { |
| 574 |
return 128; |
| 575 |
} |
| 576 |
|
| 577 |
void DivPlatformSwan::reset() { |
| 578 |
while (!writes.empty()) writes.pop(); |
| 579 |
while (!postDACWrites.empty()) postDACWrites.pop(); |
| 580 |
memset(regPool,0,128); |
| 581 |
for (int i=0; i<4; i++) { |
| 582 |
chan[i]=Channel(); |
| 583 |
chan[i].vol=15; |
| 584 |
chan[i].pan=0xff; |
| 585 |
chan[i].std.setEngine(parent); |
| 586 |
chan[i].ws.setEngine(parent); |
| 587 |
chan[i].ws.init(NULL,32,15,false); |
| 588 |
rWrite(0x08+i,0xff); |
| 589 |
} |
| 590 |
if (dumpWrites) { |
| 591 |
addWrite(0xffffffff,0); |
| 592 |
} |
| 593 |
ws_mdfn->SoundReset(); |
| 594 |
pcm=false; |
| 595 |
sweep=false; |
| 596 |
furnaceDac=false; |
| 597 |
setPos=false; |
| 598 |
noise=0; |
| 599 |
dacPeriod=0; |
| 600 |
dacRate=0; |
| 601 |
dacPos=0; |
| 602 |
dacSample=-1; |
| 603 |
sampleBank=0; |
| 604 |
rWrite(0x0f,0x00); // wave table at 0x0000 |
| 605 |
rWrite(0x11,0x09); // enable speakers |
| 606 |
} |
| 607 |
|
| 608 |
int DivPlatformSwan::getOutputCount() { |
| 609 |
return 2; |
| 610 |
} |
| 611 |
|
| 612 |
bool DivPlatformSwan::hasAcquireDirect() { |
| 613 |
return true; |
| 614 |
} |
| 615 |
|
| 616 |
void DivPlatformSwan::notifyWaveChange(int wave) { |
| 617 |
for (int i=0; i<4; i++) { |
| 618 |
if (chan[i].wave==wave) { |
| 619 |
chan[i].ws.changeWave1(wave); |
| 620 |
updateWave(i); |
| 621 |
} |
| 622 |
} |
| 623 |
} |
| 624 |
|
| 625 |
void DivPlatformSwan::notifyInsDeletion(void* ins) { |
| 626 |
for (int i=0; i<4; i++) { |
| 627 |
chan[i].std.notifyInsDeletion((DivInstrument*)ins); |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
void DivPlatformSwan::poke(unsigned int addr, unsigned short val) { |
| 632 |
rWrite(addr,val); |
| 633 |
} |
| 634 |
|
| 635 |
void DivPlatformSwan::poke(std::vector<DivRegWrite>& wlist) { |
| 636 |
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val); |
| 637 |
} |
| 638 |
|
| 639 |
void DivPlatformSwan::setFlags(const DivConfig& flags) { |
| 640 |
chipClock=3072000; |
| 641 |
CHECK_CUSTOM_CLOCK; |
| 642 |
rate=chipClock; |
| 643 |
for (int i=0; i<4; i++) { |
| 644 |
oscBuf[i]->setRate(rate); |
| 645 |
} |
| 646 |
} |
| 647 |
|
| 648 |
int DivPlatformSwan::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { |
| 649 |
parent=p; |
| 650 |
dumpWrites=false; |
| 651 |
skipRegisterWrites=false; |
| 652 |
for (int i=0; i<4; i++) { |
| 653 |
isMuted[i]=false; |
| 654 |
oscBuf[i]=new DivDispatchOscBuffer; |
| 655 |
} |
| 656 |
ws_mdfn=new WSwan(); |
| 657 |
setFlags(flags); |
| 658 |
reset(); |
| 659 |
return 4; |
| 660 |
} |
| 661 |
|
| 662 |
void DivPlatformSwan::quit() { |
| 663 |
for (int i=0; i<4; i++) { |
| 664 |
delete oscBuf[i]; |
| 665 |
} |
| 666 |
delete ws_mdfn; |
| 667 |
} |
| 668 |
|
| 669 |
DivPlatformSwan::~DivPlatformSwan() { |
| 670 |
} |