| 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 "supervision.h" |
| 21 |
#include "../engine.h" |
| 22 |
#include "../../ta-log.h" |
| 23 |
#include "furIcons.h" |
| 24 |
#include <math.h> |
| 25 |
|
| 26 |
//#define rWrite(a,v) pendingWrites[a]=v; |
| 27 |
#define rWrite(a,v) if (!skipRegisterWrites) {writes.push(QueuedWrite(a,v)); if (dumpWrites) {addWrite(a,v);} } |
| 28 |
|
| 29 |
#define CHIP_DIVIDER 32 |
| 30 |
|
| 31 |
const char* regCheatSheetSupervision[]={ |
| 32 |
"Freq0L", "10", |
| 33 |
"Freq0H", "11", |
| 34 |
"Control0", "12", |
| 35 |
"Len0", "13", |
| 36 |
|
| 37 |
"Freq1L", "14", |
| 38 |
"Freq1H", "15", |
| 39 |
"Control1", "16", |
| 40 |
"Len1", "17", |
| 41 |
|
| 42 |
"DMAstartL", "18", |
| 43 |
"DMAstartH", "19", |
| 44 |
"DMAlen", "1a", |
| 45 |
"DMAstep", "1b", |
| 46 |
"DMAon", "1c", |
| 47 |
|
| 48 |
"NoisDiv", "28", |
| 49 |
"NoisLen", "29", |
| 50 |
"NoisCtrl", "2a", |
| 51 |
|
| 52 |
NULL |
| 53 |
}; |
| 54 |
|
| 55 |
const char** DivPlatformSupervision::getRegisterSheet() { |
| 56 |
return regCheatSheetSupervision; |
| 57 |
} |
| 58 |
|
| 59 |
void DivPlatformSupervision::acquire(short** buf, size_t len) { |
| 60 |
int mask_bits=0; |
| 61 |
for (int i=0; i<4; i++) { |
| 62 |
mask_bits |= isMuted[i]?0:8>>i; |
| 63 |
} |
| 64 |
supervision_set_mute_mask(&svision,mask_bits); |
| 65 |
|
| 66 |
for (int i=0; i<4; i++) { |
| 67 |
oscBuf[i]->begin(len); |
| 68 |
} |
| 69 |
|
| 70 |
for (size_t h=0; h<len; h++) { |
| 71 |
while (!writes.empty()) { |
| 72 |
QueuedWrite w=writes.front(); |
| 73 |
supervision_memorymap_registers_write(&svision,w.addr|0x2000,w.val); |
| 74 |
regPool[w.addr&0x3f]=w.val; |
| 75 |
writes.pop(); |
| 76 |
} |
| 77 |
|
| 78 |
unsigned char s[6]; |
| 79 |
supervision_sound_stream_update(&svision,s,2); |
| 80 |
tempL[0]=(((int)s[0])-128)*256; |
| 81 |
tempR[0]=(((int)s[1])-128)*256; |
| 82 |
|
| 83 |
for (int i=0; i<4; i++) { |
| 84 |
oscBuf[i]->putSample(h,CLAMP(((int)s[2+i])<<8,-32768,32767)); |
| 85 |
} |
| 86 |
|
| 87 |
tempL[0]=(tempL[0]>>1)+(tempL[0]>>2); |
| 88 |
tempR[0]=(tempR[0]>>1)+(tempR[0]>>2); |
| 89 |
|
| 90 |
if (tempL[0]<-32768) tempL[0]=-32768; |
| 91 |
if (tempL[0]>32767) tempL[0]=32767; |
| 92 |
if (tempR[0]<-32768) tempR[0]=-32768; |
| 93 |
if (tempR[0]>32767) tempR[0]=32767; |
| 94 |
|
| 95 |
//printf("tempL: %d tempR: %d\n",tempL,tempR); |
| 96 |
buf[0][h]=tempL[0]; |
| 97 |
buf[1][h]=tempR[0]; |
| 98 |
} |
| 99 |
|
| 100 |
for (int i=0; i<4; i++) { |
| 101 |
oscBuf[i]->end(len); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
void DivPlatformSupervision::tick(bool sysTick) { |
| 106 |
for (int i=0; i<4; i++) { |
| 107 |
chan[i].std.next(); |
| 108 |
if (chan[i].std.vol.had) { |
| 109 |
chan[i].outVol=VOL_SCALE_LINEAR(chan[i].vol&15,MIN(15,chan[i].std.vol.val),15); |
| 110 |
} |
| 111 |
if (NEW_ARP_STRAT) { |
| 112 |
chan[i].handleArp(); |
| 113 |
} else if (chan[i].std.arp.had) { |
| 114 |
if (!chan[i].inPorta) { |
| 115 |
int f=parent->calcArp(chan[i].note,chan[i].std.arp.val); |
| 116 |
if (i==2 || i==3) { |
| 117 |
chan[i].baseFreq=f; |
| 118 |
//if (chan[i].baseFreq>255) chan[i].baseFreq=255; |
| 119 |
if (chan[i].baseFreq<0) chan[i].baseFreq=0; |
| 120 |
} else { |
| 121 |
chan[i].baseFreq=NOTE_PERIODIC(f); |
| 122 |
} |
| 123 |
} |
| 124 |
chan[i].freqChanged=true; |
| 125 |
} |
| 126 |
if (chan[i].std.duty.had) { |
| 127 |
chan[i].duty=chan[i].std.duty.val; |
| 128 |
} |
| 129 |
if (chan[i].std.panL.had) { |
| 130 |
chan[i].pan=chan[i].std.panL.val&3; |
| 131 |
} |
| 132 |
if (chan[i].std.pitch.had) { |
| 133 |
if (chan[i].std.pitch.mode) { |
| 134 |
chan[i].pitch2+=chan[i].std.pitch.val; |
| 135 |
CLAMP_VAR(chan[i].pitch2,-32768,32767); |
| 136 |
} else { |
| 137 |
chan[i].pitch2=chan[i].std.pitch.val; |
| 138 |
} |
| 139 |
chan[i].freqChanged=true; |
| 140 |
} |
| 141 |
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { |
| 142 |
//DivInstrument* ins=parent->getIns(chan[i].ins,DIV_INS_PCE); |
| 143 |
if (i<2) { |
| 144 |
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<<1,CHIP_DIVIDER); |
| 145 |
if (chan[i].freq<1) chan[i].freq=1; |
| 146 |
if (chan[i].freq>2047) chan[i].freq=2047; |
| 147 |
if (chan[i].freqChanged || chan[i].initWrite) { |
| 148 |
rWrite(0x10|(i<<2),chan[i].freq&0xff); |
| 149 |
rWrite(0x11|(i<<2),(chan[i].freq>>8)&0x7); |
| 150 |
} |
| 151 |
chan[i].initWrite=false; |
| 152 |
} else if (i==3) { |
| 153 |
int ntPos=chan[i].baseFreq; |
| 154 |
if (NEW_ARP_STRAT) { |
| 155 |
if (chan[i].fixedArp) { |
| 156 |
ntPos=chan[i].baseNoteOverride; |
| 157 |
} else { |
| 158 |
ntPos+=chan[i].arpOff; |
| 159 |
} |
| 160 |
} |
| 161 |
ntPos+=chan[i].pitch2; |
| 162 |
chan[i].freq=15-(ntPos&15); |
| 163 |
unsigned char r=(chan[i].freq<<4)|(chan[i].outVol&0xf); |
| 164 |
rWrite(0x28,r); |
| 165 |
noiseReg[0]=r; |
| 166 |
rWrite(0x29,0xc8); |
| 167 |
r=((chan[i].duty&1)^dutySwap)|(0x02|0x10)|(chan[i].pan<<2); |
| 168 |
rWrite(0x2A,r); |
| 169 |
} |
| 170 |
if (chan[i].keyOn && i==2) { |
| 171 |
if (chan[i].pcm) { |
| 172 |
int ntPos=chan[i].sampleNote; |
| 173 |
ntPos+=chan[i].pitch2; |
| 174 |
chan[i].freq=3-(ntPos&3); |
| 175 |
int sNum=chan[i].sample; |
| 176 |
DivSample* sample=parent->getSample(sNum); |
| 177 |
if (sample!=NULL && sNum>=0 && sNum<parent->song.sampleLen) { |
| 178 |
unsigned int off=MIN(sampleOff[sNum]+chan[i].hasOffset,sampleOff[sNum]+sampleLen[sNum]); |
| 179 |
unsigned int len=MAX((((int)sampleLen[sNum])-((int)chan[i].hasOffset)),0); |
| 180 |
if (len) { |
| 181 |
rWrite(0x18,off&0xff); |
| 182 |
rWrite(0x19,(off>>8&0x3f)|0x80); |
| 183 |
rWrite(0x1A,MIN(MAX(len>>4,0),255)); |
| 184 |
rWrite(0x1B,chan[i].freq|((chan[i].pan&3)<<2)|((off>>14&7)<<4)); |
| 185 |
rWrite(0x1C,0x80); |
| 186 |
} |
| 187 |
sampleOffset=chan[i].hasOffset; |
| 188 |
chan[i].hasOffset=0; |
| 189 |
} |
| 190 |
} |
| 191 |
} |
| 192 |
if (chan[i].keyOff && i==2) { |
| 193 |
if (chan[i].pcm) { |
| 194 |
int ntPos=chan[i].sampleNote; |
| 195 |
ntPos+=chan[i].pitch2; |
| 196 |
chan[i].freq=3-(ntPos&3); |
| 197 |
int sNum=chan[i].sample; |
| 198 |
DivSample* sample=parent->getSample(sNum); |
| 199 |
if (sample!=NULL && sNum>=0 && sNum<parent->song.sampleLen) { |
| 200 |
rWrite(0x1C,0x00); |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
if (chan[i].keyOn) chan[i].kon=true; |
| 205 |
if (chan[i].keyOff) chan[i].kon=false; |
| 206 |
if (chan[i].keyOn) chan[i].keyOn=false; |
| 207 |
if (chan[i].keyOff) chan[i].keyOff=false; |
| 208 |
chan[i].freqChanged=false; |
| 209 |
} |
| 210 |
|
| 211 |
if (chan[i].kon) { |
| 212 |
if (i<2) { |
| 213 |
rWrite(0x12|(i<<2),(chan[i].outVol&0xf)|((chan[i].duty&3)<<4)); |
| 214 |
rWrite(0x13|(i<<2),0xc8); |
| 215 |
} else if (i == 3) { |
| 216 |
int ntPos=chan[i].baseFreq; |
| 217 |
if (NEW_ARP_STRAT) { |
| 218 |
if (chan[i].fixedArp) { |
| 219 |
ntPos=chan[i].baseNoteOverride; |
| 220 |
} else { |
| 221 |
ntPos+=chan[i].arpOff; |
| 222 |
} |
| 223 |
} |
| 224 |
ntPos+=chan[i].pitch2; |
| 225 |
chan[i].freq=15-(ntPos&15); |
| 226 |
unsigned char r=(chan[i].freq<<4)|(chan[i].outVol&0xf); |
| 227 |
if (noiseReg[0] != r) rWrite(0x28,r); |
| 228 |
noiseReg[0]=r; |
| 229 |
rWrite(0x29,0xc8); |
| 230 |
r=((chan[i].duty&1)^dutySwap)|(0x02|0x10)|(chan[i].pan<<2); |
| 231 |
if (noiseReg[2] != r) rWrite(0x2A,r); |
| 232 |
noiseReg[2]=r; |
| 233 |
} else if (i==2) { |
| 234 |
if (chan[i].pcm) { |
| 235 |
int ntPos=chan[i].sampleNote; |
| 236 |
ntPos+=chan[i].pitch2; |
| 237 |
chan[i].freq=3-(ntPos&3); |
| 238 |
int sNum=chan[i].sample; |
| 239 |
DivSample* sample=parent->getSample(sNum); |
| 240 |
if (sample!=NULL && sNum>=0 && sNum<parent->song.sampleLen) { |
| 241 |
unsigned int off=MIN(sampleOff[sNum]+sampleOffset,sampleOff[sNum]+sampleLen[sNum]); |
| 242 |
unsigned int len=MAX((((int)sampleLen[sNum])-((int)sampleOffset)),0); |
| 243 |
if (len) { |
| 244 |
rWrite(0x1A,MIN(MAX(len>>4,0),255)); |
| 245 |
if (chan[i].outVol==0) { |
| 246 |
rWrite(0x1B,chan[i].freq|((off>>14&7)<<4)); |
| 247 |
} else { |
| 248 |
rWrite(0x1B,chan[i].freq|((chan[i].pan&3)<<2)|((off>>14&7)<<4)); |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
} else { |
| 255 |
if (i < 2) { |
| 256 |
rWrite(0x12|(i<<2),0); |
| 257 |
rWrite(0x13|(i<<2),0xc8); |
| 258 |
} else if (i == 3) { |
| 259 |
rWrite(0x29,0); |
| 260 |
unsigned char r=0; |
| 261 |
if (noiseReg[2] != r) rWrite(0x2A,r); |
| 262 |
noiseReg[2]=r; |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
int DivPlatformSupervision::dispatch(DivCommand c) { |
| 270 |
switch (c.cmd) { |
| 271 |
case DIV_CMD_NOTE_ON: { |
| 272 |
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_SUPERVISION); |
| 273 |
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { |
| 274 |
chan[c.chan].pcm=true; |
| 275 |
} else { |
| 276 |
chan[c.chan].pcm=false; |
| 277 |
} |
| 278 |
if (chan[c.chan].pcm) { |
| 279 |
if (c.value!=DIV_NOTE_NULL) { |
| 280 |
chan[c.chan].sample=ins->amiga.getSample(c.value); |
| 281 |
chan[c.chan].sampleNote=c.value; |
| 282 |
if (c.chan==2) { |
| 283 |
c.value=ins->amiga.getFreq(c.value); |
| 284 |
chan[c.chan].sampleNote=c.value; |
| 285 |
} |
| 286 |
} |
| 287 |
} else { |
| 288 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 289 |
chan[c.chan].sampleNoteDelta=0; |
| 290 |
} |
| 291 |
if (c.value!=DIV_NOTE_NULL) { |
| 292 |
chan[c.chan].baseFreq=c.chan==3?c.value:NOTE_PERIODIC(c.value); |
| 293 |
chan[c.chan].freqChanged=true; |
| 294 |
chan[c.chan].note=c.value; |
| 295 |
} |
| 296 |
chan[c.chan].active=true; |
| 297 |
chan[c.chan].keyOn=true; |
| 298 |
//chwrite(c.chan,0x04,0x80|chan[c.chan].vol); |
| 299 |
chan[c.chan].macroInit(ins); |
| 300 |
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { |
| 301 |
chan[c.chan].outVol=chan[c.chan].vol; |
| 302 |
} |
| 303 |
chan[c.chan].insChanged=false; |
| 304 |
break; |
| 305 |
} |
| 306 |
case DIV_CMD_NOTE_OFF: |
| 307 |
if (dumpWrites) addWrite(0xffff0002+(c.chan<<8),0); |
| 308 |
chan[c.chan].active=false; |
| 309 |
chan[c.chan].keyOff=true; |
| 310 |
chan[c.chan].macroInit(NULL); |
| 311 |
break; |
| 312 |
case DIV_CMD_NOTE_OFF_ENV: |
| 313 |
case DIV_CMD_ENV_RELEASE: |
| 314 |
chan[c.chan].std.release(); |
| 315 |
break; |
| 316 |
case DIV_CMD_INSTRUMENT: |
| 317 |
if (chan[c.chan].ins!=c.value || c.value2==1) { |
| 318 |
chan[c.chan].ins=c.value; |
| 319 |
chan[c.chan].insChanged=true; |
| 320 |
} |
| 321 |
break; |
| 322 |
case DIV_CMD_VOLUME: |
| 323 |
if (chan[c.chan].vol!=c.value) { |
| 324 |
chan[c.chan].vol=c.value; |
| 325 |
if (!chan[c.chan].std.vol.has) { |
| 326 |
chan[c.chan].outVol=c.value; |
| 327 |
if (chan[c.chan].active) { |
| 328 |
//chwrite(c.chan,0x04,0x80|chan[c.chan].outVol); |
| 329 |
} |
| 330 |
} |
| 331 |
} |
| 332 |
break; |
| 333 |
case DIV_CMD_GET_VOLUME: |
| 334 |
if (chan[c.chan].std.vol.has) { |
| 335 |
return chan[c.chan].vol; |
| 336 |
} |
| 337 |
return chan[c.chan].outVol; |
| 338 |
break; |
| 339 |
case DIV_CMD_PITCH: |
| 340 |
chan[c.chan].pitch=c.value; |
| 341 |
chan[c.chan].freqChanged=true; |
| 342 |
break; |
| 343 |
case DIV_CMD_NOTE_PORTA: { |
| 344 |
int destFreq=NOTE_PERIODIC(c.value2+chan[c.chan].sampleNoteDelta); |
| 345 |
bool return2=false; |
| 346 |
if (destFreq>chan[c.chan].baseFreq) { |
| 347 |
chan[c.chan].baseFreq+=c.value; |
| 348 |
if (chan[c.chan].baseFreq>=destFreq) { |
| 349 |
chan[c.chan].baseFreq=destFreq; |
| 350 |
return2=true; |
| 351 |
} |
| 352 |
} else { |
| 353 |
chan[c.chan].baseFreq-=c.value; |
| 354 |
if (chan[c.chan].baseFreq<=destFreq) { |
| 355 |
chan[c.chan].baseFreq=destFreq; |
| 356 |
return2=true; |
| 357 |
} |
| 358 |
} |
| 359 |
chan[c.chan].freqChanged=true; |
| 360 |
if (return2) { |
| 361 |
chan[c.chan].inPorta=false; |
| 362 |
return 2; |
| 363 |
} |
| 364 |
break; |
| 365 |
} |
| 366 |
case DIV_CMD_STD_NOISE_MODE: |
| 367 |
chan[c.chan].duty=c.value; |
| 368 |
break; |
| 369 |
case DIV_CMD_SAMPLE_POS: |
| 370 |
chan[c.chan].hasOffset=c.value; |
| 371 |
chan[c.chan].keyOn=true; |
| 372 |
break; |
| 373 |
case DIV_CMD_PANNING: { |
| 374 |
chan[c.chan].pan=0; |
| 375 |
if (c.value&0xf0) chan[c.chan].pan|=2; |
| 376 |
if (c.value2>>4) chan[c.chan].pan|=1; |
| 377 |
if (chan[c.chan].pan==0) chan[c.chan].pan=3; |
| 378 |
break; |
| 379 |
} |
| 380 |
case DIV_CMD_LEGATO: |
| 381 |
chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+chan[c.chan].sampleNoteDelta+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0))); |
| 382 |
chan[c.chan].freqChanged=true; |
| 383 |
chan[c.chan].note=c.value; |
| 384 |
break; |
| 385 |
case DIV_CMD_PRE_PORTA: |
| 386 |
if (chan[c.chan].active && c.value2) { |
| 387 |
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_SUPERVISION)); |
| 388 |
} |
| 389 |
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); |
| 390 |
chan[c.chan].inPorta=c.value; |
| 391 |
break; |
| 392 |
case DIV_CMD_GET_VOLMAX: |
| 393 |
return 15; |
| 394 |
break; |
| 395 |
case DIV_CMD_MACRO_OFF: |
| 396 |
chan[c.chan].std.mask(c.value,true); |
| 397 |
break; |
| 398 |
case DIV_CMD_MACRO_ON: |
| 399 |
chan[c.chan].std.mask(c.value,false); |
| 400 |
break; |
| 401 |
case DIV_CMD_MACRO_RESTART: |
| 402 |
chan[c.chan].std.restart(c.value); |
| 403 |
break; |
| 404 |
default: |
| 405 |
break; |
| 406 |
} |
| 407 |
return 1; |
| 408 |
} |
| 409 |
|
| 410 |
void DivPlatformSupervision::muteChannel(int ch, bool mute) { |
| 411 |
isMuted[ch]=mute; |
| 412 |
} |
| 413 |
|
| 414 |
void DivPlatformSupervision::forceIns() { |
| 415 |
for (int i=0; i<4; i++) { |
| 416 |
chan[i].insChanged=true; |
| 417 |
chan[i].freqChanged=true; |
| 418 |
//chwrite(i,0x05,isMuted[i]?0:chan[i].pan); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
void* DivPlatformSupervision::getChanState(int ch) { |
| 423 |
return &chan[ch]; |
| 424 |
} |
| 425 |
|
| 426 |
DivMacroInt* DivPlatformSupervision::getChanMacroInt(int ch) { |
| 427 |
return &chan[ch].std; |
| 428 |
} |
| 429 |
|
| 430 |
DivDispatchOscBuffer* DivPlatformSupervision::getOscBuffer(int ch) { |
| 431 |
return oscBuf[ch]; |
| 432 |
} |
| 433 |
|
| 434 |
unsigned char* DivPlatformSupervision::getRegisterPool() { |
| 435 |
return regPool; |
| 436 |
} |
| 437 |
|
| 438 |
int DivPlatformSupervision::getRegisterPoolSize() { |
| 439 |
return 64; |
| 440 |
} |
| 441 |
|
| 442 |
void DivPlatformSupervision::reset() { |
| 443 |
writes.clear(); |
| 444 |
memset(regPool,0,64); |
| 445 |
for (int i=0; i<4; i++) { |
| 446 |
chan[i]=DivPlatformSupervision::Channel(); |
| 447 |
chan[i].std.setEngine(parent); |
| 448 |
} |
| 449 |
if (dumpWrites) { |
| 450 |
addWrite(0xffffffff,0); |
| 451 |
} |
| 452 |
supervision_sound_reset(&svision); |
| 453 |
memset(tempL,0,32*sizeof(int)); |
| 454 |
memset(tempR,0,32*sizeof(int)); |
| 455 |
memset(noiseReg,0,3*sizeof(unsigned char)); |
| 456 |
noiseReg[2]=0xff; |
| 457 |
sampleOffset=0; |
| 458 |
} |
| 459 |
|
| 460 |
int DivPlatformSupervision::getOutputCount() { |
| 461 |
return 2; |
| 462 |
} |
| 463 |
|
| 464 |
bool DivPlatformSupervision::keyOffAffectsArp(int ch) { |
| 465 |
return true; |
| 466 |
} |
| 467 |
|
| 468 |
void DivPlatformSupervision::notifyInsDeletion(void* ins) { |
| 469 |
for (int i=0; i<4; i++) { |
| 470 |
chan[i].std.notifyInsDeletion((DivInstrument*)ins); |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
void DivPlatformSupervision::setFlags(const DivConfig& flags) { |
| 475 |
if (flags.getInt("swapDuty",true)) { |
| 476 |
dutySwap=1; |
| 477 |
} else { |
| 478 |
dutySwap=0; |
| 479 |
} |
| 480 |
otherFlags=0; |
| 481 |
if (flags.getInt("sqStereo",false)) { |
| 482 |
otherFlags |= 1; |
| 483 |
} |
| 484 |
chipClock=4000000; |
| 485 |
CHECK_CUSTOM_CLOCK; |
| 486 |
rate=chipClock/64; |
| 487 |
for (int i=0; i<4; i++) { |
| 488 |
oscBuf[i]->setRate(rate); |
| 489 |
} |
| 490 |
supervision_sound_set_clock(&svision,(unsigned int)chipClock); |
| 491 |
supervision_sound_set_flags(&svision,(unsigned int)otherFlags); |
| 492 |
} |
| 493 |
|
| 494 |
void DivPlatformSupervision::poke(unsigned int addr, unsigned short val) { |
| 495 |
rWrite(addr,val); |
| 496 |
} |
| 497 |
|
| 498 |
void DivPlatformSupervision::poke(std::vector<DivRegWrite>& wlist) { |
| 499 |
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val); |
| 500 |
} |
| 501 |
|
| 502 |
const void* DivPlatformSupervision::getSampleMem(int index) { |
| 503 |
return index==0?sampleMem:NULL; |
| 504 |
} |
| 505 |
|
| 506 |
size_t DivPlatformSupervision::getSampleMemCapacity(int index) { |
| 507 |
return index==0?65536:0; |
| 508 |
} |
| 509 |
|
| 510 |
size_t DivPlatformSupervision::getSampleMemUsage(int index) { |
| 511 |
return index==0?sampleMemLen:0; |
| 512 |
} |
| 513 |
|
| 514 |
bool DivPlatformSupervision::isSampleLoaded(int index, int sample) { |
| 515 |
if (index!=0) return false; |
| 516 |
if (sample<0 || sample>32767) return false; |
| 517 |
return sampleLoaded[sample]; |
| 518 |
} |
| 519 |
|
| 520 |
const DivMemoryComposition* DivPlatformSupervision::getMemCompo(int index) { |
| 521 |
if (index!=0) return NULL; |
| 522 |
return &memCompo; |
| 523 |
} |
| 524 |
|
| 525 |
void DivPlatformSupervision::renderSamples(int sysID) { |
| 526 |
memset(sampleMem,0,getSampleMemCapacity(0)); |
| 527 |
memset(sampleLoaded,0,32768*sizeof(bool)); |
| 528 |
|
| 529 |
memCompo=DivMemoryComposition(); |
| 530 |
memCompo.name="Sample Memory"; |
| 531 |
|
| 532 |
size_t memPos=0; |
| 533 |
for (int i=0; i<parent->song.sampleLen; i++) { |
| 534 |
DivSample* s=parent->song.sample[i]; |
| 535 |
if (!s->renderOn[0][sysID]) { |
| 536 |
sampleOff[i]=0; |
| 537 |
continue; |
| 538 |
} |
| 539 |
unsigned int paddedLen=((s->length8>>1)+31)&(~0x1f); |
| 540 |
logV("%d padded length: %d",i,paddedLen); |
| 541 |
if (paddedLen>=4096) { |
| 542 |
paddedLen=4096; |
| 543 |
} |
| 544 |
if ((memPos&(~0x3fff))!=((memPos+paddedLen)&(~0x3fff))) { |
| 545 |
memPos=(memPos+0x3fff)&(~0x3fff); |
| 546 |
} |
| 547 |
if (memPos>=getSampleMemCapacity(0)) { |
| 548 |
logW("out of memory for sample %d!",i); |
| 549 |
break; |
| 550 |
} |
| 551 |
if (memPos+paddedLen>=getSampleMemCapacity(0)) { |
| 552 |
sampleLen[i]=(getSampleMemCapacity(0)-memPos)>>1; |
| 553 |
for (size_t i=0; i<(getSampleMemCapacity(0)-memPos)>>1; i++) { |
| 554 |
sampleMem[memPos+i]=(((s->data8[i*2+0]+128)>>4)<<4&0xf0)|(((s->data8[i*2+1]+128)>>4)&0xf); |
| 555 |
} |
| 556 |
logW("out of memory for sample %d!",i); |
| 557 |
} else { |
| 558 |
size_t len=MIN((s->length8>>1),paddedLen); |
| 559 |
sampleLen[i]=(unsigned int)(len); |
| 560 |
for (size_t i=0; i<len; i++) { |
| 561 |
sampleMem[memPos+i]=(((s->data8[i*2+0]+128)>>4)<<4&0xf0)|(((s->data8[i*2+1]+128)>>4)&0xf); |
| 562 |
} |
| 563 |
sampleLoaded[i]=true; |
| 564 |
} |
| 565 |
sampleOff[i]=memPos; |
| 566 |
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+paddedLen)); |
| 567 |
memPos+=paddedLen; |
| 568 |
} |
| 569 |
sampleMemLen=memPos; |
| 570 |
|
| 571 |
memCompo.capacity=65536; |
| 572 |
memCompo.used=sampleMemLen; |
| 573 |
} |
| 574 |
|
| 575 |
bool DivPlatformSupervision::getDCOffRequired() { |
| 576 |
return true; |
| 577 |
} |
| 578 |
|
| 579 |
int DivPlatformSupervision::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { |
| 580 |
parent=p; |
| 581 |
dumpWrites=false; |
| 582 |
skipRegisterWrites=false; |
| 583 |
for (int i=0; i<4; i++) { |
| 584 |
isMuted[i]=false; |
| 585 |
oscBuf[i]=new DivDispatchOscBuffer; |
| 586 |
} |
| 587 |
sampleMem=svision.supervision_dma_mem; |
| 588 |
dutySwap=0; |
| 589 |
otherFlags=0; |
| 590 |
sampleOffset=0; |
| 591 |
sampleMemLen=0; |
| 592 |
memset(sampleMem,0,65536); |
| 593 |
svision.ch_mask=15; |
| 594 |
svision.flags=1; |
| 595 |
setFlags(flags); |
| 596 |
reset(); |
| 597 |
return 4; |
| 598 |
} |
| 599 |
|
| 600 |
void DivPlatformSupervision::quit() { |
| 601 |
for (int i=0; i<4; i++) { |
| 602 |
delete oscBuf[i]; |
| 603 |
} |
| 604 |
} |
| 605 |
|
| 606 |
// initialization of important arrays |
| 607 |
DivPlatformSupervision::DivPlatformSupervision() { |
| 608 |
sampleOff=new unsigned int[32768]; |
| 609 |
sampleLen=new unsigned int[32768]; |
| 610 |
sampleLoaded=new bool[32768]; |
| 611 |
} |
| 612 |
|
| 613 |
DivPlatformSupervision::~DivPlatformSupervision() { |
| 614 |
delete[] sampleOff; |
| 615 |
delete[] sampleLen; |
| 616 |
delete[] sampleLoaded; |
| 617 |
} |