| 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 "x1_010.h" |
| 21 |
#include "../engine.h" |
| 22 |
#include "../../ta-log.h" |
| 23 |
#include <math.h> |
| 24 |
|
| 25 |
//#define rWrite(a,v) pendingWrites[a]=v; |
| 26 |
#define rWrite(a,v) if (!skipRegisterWrites) { x1_010.ram_w(a,v); if (dumpWrites) { addWrite(a,v); } } |
| 27 |
|
| 28 |
#define chRead(c,a) x1_010.ram_r((c<<3)|(a&7)) |
| 29 |
#define chWrite(c,a,v) rWrite((c<<3)|(a&7),v) |
| 30 |
#define waveWrite(c,a,v) rWrite(0x1000|(chan[c].waveBank<<11)|(c<<7)|(a&0x7f),(v-128)&0xff) |
| 31 |
#define envFill(c,a) rWrite(0x800|(c<<7)|(a&0x7f),(chan[c].lvol<<4)|chan[c].rvol) |
| 32 |
#define envWrite(c,a,l,r) rWrite(0x800|(c<<7)|(a&0x7f),(((chan[c].lvol*(l))/15)<<4)|((chan[c].rvol*(r))/15)) |
| 33 |
|
| 34 |
#define refreshControl(c) chWrite(c,0,chan[c].active?(chan[c].pcm?1:((chan[c].env.flag.envEnable && chan[c].env.flag.envOneshot)?7:3)):0); |
| 35 |
|
| 36 |
#define CHIP_FREQBASE 4194304 |
| 37 |
|
| 38 |
const char* regCheatSheetX1_010[]={ |
| 39 |
// Channel registers |
| 40 |
"Ch00_Control", "0000", |
| 41 |
"Ch00_PCMVol_WavSel", "0001", |
| 42 |
"Ch00_FreqL", "0002", |
| 43 |
"Ch00_FreqH", "0003", |
| 44 |
"Ch00_Start_EnvFrq", "0004", |
| 45 |
"Ch00_End_EnvSel", "0005", |
| 46 |
"Ch01_Control", "0008", |
| 47 |
"Ch01_PCMVol_WavSel", "0009", |
| 48 |
"Ch01_FreqL", "000A", |
| 49 |
"Ch01_FreqH", "000B", |
| 50 |
"Ch01_Start_EnvFrq", "000C", |
| 51 |
"Ch01_End_EnvSel", "000D", |
| 52 |
"Ch02_Control", "0010", |
| 53 |
"Ch02_PCMVol_WavSel", "0011", |
| 54 |
"Ch02_FreqL", "0012", |
| 55 |
"Ch02_FreqH", "0013", |
| 56 |
"Ch02_Start_EnvFrq", "0014", |
| 57 |
"Ch02_End_EnvSel", "0015", |
| 58 |
"Ch03_Control", "0018", |
| 59 |
"Ch03_PCMVol_WavSel", "0019", |
| 60 |
"Ch03_FreqL", "001A", |
| 61 |
"Ch03_FreqH", "001B", |
| 62 |
"Ch03_Start_EnvFrq", "001C", |
| 63 |
"Ch03_End_EnvSel", "001D", |
| 64 |
"Ch04_Control", "0020", |
| 65 |
"Ch04_PCMVol_WavSel", "0021", |
| 66 |
"Ch04_FreqL", "0022", |
| 67 |
"Ch04_FreqH", "0023", |
| 68 |
"Ch04_Start_EnvFrq", "0024", |
| 69 |
"Ch04_End_EnvSel", "0025", |
| 70 |
"Ch05_Control", "0028", |
| 71 |
"Ch05_PCMVol_WavSel", "0029", |
| 72 |
"Ch05_FreqL", "002A", |
| 73 |
"Ch05_FreqH", "002B", |
| 74 |
"Ch05_Start_EnvFrq", "002C", |
| 75 |
"Ch05_End_EnvSel", "002D", |
| 76 |
"Ch06_Control", "0030", |
| 77 |
"Ch06_PCMVol_WavSel", "0031", |
| 78 |
"Ch06_FreqL", "0032", |
| 79 |
"Ch06_FreqH", "0033", |
| 80 |
"Ch06_Start_EnvFrq", "0034", |
| 81 |
"Ch06_End_EnvSel", "0035", |
| 82 |
"Ch07_Control", "0038", |
| 83 |
"Ch07_PCMVol_WavSel", "0039", |
| 84 |
"Ch07_FreqL", "003A", |
| 85 |
"Ch07_FreqH", "003B", |
| 86 |
"Ch07_Start_EnvFrq", "003C", |
| 87 |
"Ch07_End_EnvSel", "003D", |
| 88 |
"Ch08_Control", "0040", |
| 89 |
"Ch08_PCMVol_WavSel", "0041", |
| 90 |
"Ch08_FreqL", "0042", |
| 91 |
"Ch08_FreqH", "0043", |
| 92 |
"Ch08_Start_EnvFrq", "0044", |
| 93 |
"Ch08_End_EnvSel", "0045", |
| 94 |
"Ch09_Control", "0048", |
| 95 |
"Ch09_PCMVol_WavSel", "0049", |
| 96 |
"Ch09_FreqL", "004A", |
| 97 |
"Ch09_FreqH", "004B", |
| 98 |
"Ch09_Start_EnvFrq", "004C", |
| 99 |
"Ch09_End_EnvSel", "004D", |
| 100 |
"Ch10_Control", "0050", |
| 101 |
"Ch10_PCMVol_WavSel", "0051", |
| 102 |
"Ch10_FreqL", "0052", |
| 103 |
"Ch10_FreqH", "0053", |
| 104 |
"Ch10_Start_EnvFrq", "0054", |
| 105 |
"Ch10_End_EnvSel", "0055", |
| 106 |
"Ch11_Control", "0058", |
| 107 |
"Ch11_PCMVol_WavSel", "0059", |
| 108 |
"Ch11_FreqL", "005A", |
| 109 |
"Ch11_FreqH", "005B", |
| 110 |
"Ch11_Start_EnvFrq", "005C", |
| 111 |
"Ch11_End_EnvSel", "005D", |
| 112 |
"Ch12_Control", "0060", |
| 113 |
"Ch12_PCMVol_WavSel", "0061", |
| 114 |
"Ch12_FreqL", "0062", |
| 115 |
"Ch12_FreqH", "0063", |
| 116 |
"Ch12_Start_EnvFrq", "0064", |
| 117 |
"Ch12_End_EnvSel", "0065", |
| 118 |
"Ch13_Control", "0068", |
| 119 |
"Ch13_PCMVol_WavSel", "0069", |
| 120 |
"Ch13_FreqL", "006A", |
| 121 |
"Ch13_FreqH", "006B", |
| 122 |
"Ch13_Start_EnvFrq", "006C", |
| 123 |
"Ch13_End_EnvSel", "006D", |
| 124 |
"Ch14_Control", "0070", |
| 125 |
"Ch14_PCMVol_WavSel", "0071", |
| 126 |
"Ch14_FreqL", "0072", |
| 127 |
"Ch14_FreqH", "0073", |
| 128 |
"Ch14_Start_EnvFrq", "0074", |
| 129 |
"Ch14_End_EnvSel", "0075", |
| 130 |
"Ch15_Control", "0078", |
| 131 |
"Ch15_PCMVol_WavSel", "0079", |
| 132 |
"Ch15_FreqL", "007A", |
| 133 |
"Ch15_FreqH", "007B", |
| 134 |
"Ch15_Start_EnvFrq", "007C", |
| 135 |
"Ch15_End_EnvSel", "007D", |
| 136 |
// Envelope data |
| 137 |
"Env01Data", "0080", |
| 138 |
"Env02Data", "0100", |
| 139 |
"Env03Data", "0180", |
| 140 |
"Env04Data", "0200", |
| 141 |
"Env05Data", "0280", |
| 142 |
"Env06Data", "0300", |
| 143 |
"Env07Data", "0380", |
| 144 |
"Env08Data", "0400", |
| 145 |
"Env09Data", "0480", |
| 146 |
"Env10Data", "0500", |
| 147 |
"Env11Data", "0580", |
| 148 |
"Env12Data", "0600", |
| 149 |
"Env13Data", "0680", |
| 150 |
"Env14Data", "0700", |
| 151 |
"Env15Data", "0780", |
| 152 |
"Env16Data", "0800", |
| 153 |
"Env17Data", "0880", |
| 154 |
"Env18Data", "0900", |
| 155 |
"Env19Data", "0980", |
| 156 |
"Env20Data", "0A00", |
| 157 |
"Env21Data", "0A80", |
| 158 |
"Env22Data", "0B00", |
| 159 |
"Env23Data", "0B80", |
| 160 |
"Env24Data", "0C00", |
| 161 |
"Env25Data", "0C80", |
| 162 |
"Env26Data", "0D00", |
| 163 |
"Env27Data", "0D80", |
| 164 |
"Env28Data", "0E00", |
| 165 |
"Env29Data", "0E80", |
| 166 |
"Env30Data", "0F00", |
| 167 |
"Env31Data", "0F80", |
| 168 |
// Wavetable data |
| 169 |
"Wave00Data", "1000", |
| 170 |
"Wave01Data", "1080", |
| 171 |
"Wave02Data", "1100", |
| 172 |
"Wave03Data", "1180", |
| 173 |
"Wave04Data", "1200", |
| 174 |
"Wave05Data", "1280", |
| 175 |
"Wave06Data", "1300", |
| 176 |
"Wave07Data", "1380", |
| 177 |
"Wave08Data", "1400", |
| 178 |
"Wave09Data", "1480", |
| 179 |
"Wave10Data", "1500", |
| 180 |
"Wave11Data", "1580", |
| 181 |
"Wave12Data", "1600", |
| 182 |
"Wave13Data", "1680", |
| 183 |
"Wave14Data", "1700", |
| 184 |
"Wave15Data", "1780", |
| 185 |
"Wave16Data", "1800", |
| 186 |
"Wave17Data", "1880", |
| 187 |
"Wave18Data", "1900", |
| 188 |
"Wave19Data", "1980", |
| 189 |
"Wave20Data", "1A00", |
| 190 |
"Wave21Data", "1A80", |
| 191 |
"Wave22Data", "1B00", |
| 192 |
"Wave23Data", "1B80", |
| 193 |
"Wave24Data", "1C00", |
| 194 |
"Wave25Data", "1C80", |
| 195 |
"Wave26Data", "1D00", |
| 196 |
"Wave27Data", "1D80", |
| 197 |
"Wave28Data", "1E00", |
| 198 |
"Wave29Data", "1E80", |
| 199 |
"Wave30Data", "1F00", |
| 200 |
"Wave31Data", "1F80", |
| 201 |
NULL |
| 202 |
}; |
| 203 |
|
| 204 |
const char** DivPlatformX1_010::getRegisterSheet() { |
| 205 |
return regCheatSheetX1_010; |
| 206 |
} |
| 207 |
|
| 208 |
void DivPlatformX1_010::acquire(short** buf, size_t len) { |
| 209 |
for (int i=0; i<16; i++) { |
| 210 |
oscBuf[i]->begin(len); |
| 211 |
} |
| 212 |
|
| 213 |
for (size_t h=0; h<len; h++) { |
| 214 |
x1_010.tick(); |
| 215 |
|
| 216 |
signed int tempL=x1_010.output(0); |
| 217 |
signed int tempR=x1_010.output(1); |
| 218 |
|
| 219 |
if (tempL<-32768) tempL=-32768; |
| 220 |
if (tempL>32767) tempL=32767; |
| 221 |
if (tempR<-32768) tempR=-32768; |
| 222 |
if (tempR>32767) tempR=32767; |
| 223 |
|
| 224 |
//printf("tempL: %d tempR: %d\n",tempL,tempR); |
| 225 |
buf[0][h]=stereo?tempL:((tempL+tempR)>>1); |
| 226 |
if (stereo) buf[1][h]=tempR; |
| 227 |
|
| 228 |
for (int i=0; i<16; i++) { |
| 229 |
int vo=(x1_010.voice_out(i,0)+x1_010.voice_out(i,1))<<2; |
| 230 |
oscBuf[i]->putSample(h,CLAMP(vo,-32768,32767)); |
| 231 |
} |
| 232 |
} |
| 233 |
|
| 234 |
for (int i=0; i<16; i++) { |
| 235 |
oscBuf[i]->end(len); |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
u8 DivPlatformX1_010::read_byte(u32 address) { |
| 240 |
if ((sampleMem!=NULL) && (address<getSampleMemCapacity())) { |
| 241 |
if (isBanked) { |
| 242 |
address=((bankSlot[(address>>17)&7]<<17)|(address&0x1ffff))&0xffffff; |
| 243 |
} else { |
| 244 |
address&=0xfffff; |
| 245 |
} |
| 246 |
return sampleMem[address]; |
| 247 |
} |
| 248 |
return 0; |
| 249 |
} |
| 250 |
|
| 251 |
double DivPlatformX1_010::NoteX1_010(int ch, int note) { |
| 252 |
if (chan[ch].pcm) { // PCM note |
| 253 |
double off=8192.0; |
| 254 |
int sample=chan[ch].sample; |
| 255 |
if (sample>=0 && sample<parent->song.sampleLen) { |
| 256 |
DivSample* s=parent->getSample(sample); |
| 257 |
if (s->centerRate<1) { |
| 258 |
off=8192.0; |
| 259 |
} else { |
| 260 |
off=8192.0*(s->centerRate/parent->getCenterRate()); |
| 261 |
} |
| 262 |
} |
| 263 |
return parent->calcBaseFreq(chipClock,off,note,false); |
| 264 |
} |
| 265 |
// Wavetable note |
| 266 |
return NOTE_FREQUENCY(note); |
| 267 |
} |
| 268 |
|
| 269 |
void DivPlatformX1_010::updateWave(int ch) { |
| 270 |
if (chan[ch].active) { |
| 271 |
chan[ch].waveBank^=1; |
| 272 |
} |
| 273 |
for (int i=0; i<128; i++) { |
| 274 |
int data=chan[ch].ws.output[i]; |
| 275 |
waveWrite(ch,i,data); |
| 276 |
} |
| 277 |
if (!chan[ch].pcm) { |
| 278 |
chWrite(ch,1,(chan[ch].waveBank<<4)|(ch&0xf)); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
void DivPlatformX1_010::updateEnvelope(int ch) { |
| 283 |
if (!chan[ch].pcm) { |
| 284 |
if (isMuted[ch]) { |
| 285 |
for (int i=0; i<128; i++) { |
| 286 |
rWrite(0x800|(ch<<7)|(i&0x7f),0); |
| 287 |
} |
| 288 |
} else { |
| 289 |
if (!chan[ch].env.flag.envEnable) { |
| 290 |
for (int i=0; i<128; i++) { |
| 291 |
envFill(ch,i); |
| 292 |
} |
| 293 |
} else { |
| 294 |
DivWavetable* wt=parent->getWave(chan[ch].env.shape); |
| 295 |
for (int i=0; i<128; i++) { |
| 296 |
if (wt->max<1 || wt->len<1) { |
| 297 |
envFill(ch,i); |
| 298 |
} else if (chan[ch].env.flag.envSplit || chan[ch].env.flag.envHinvR || chan[ch].env.flag.envVinvR || chan[ch].env.flag.envHinvL || chan[ch].env.flag.envVinvL) { // Stereo config |
| 299 |
int la=i,ra=i; |
| 300 |
int lo,ro; |
| 301 |
if (chan[ch].env.flag.envHinvR) { ra=127-i; } // horizontal invert right envelope |
| 302 |
if (chan[ch].env.flag.envHinvL) { la=127-i; } // horizontal invert left envelope |
| 303 |
if (chan[ch].env.flag.envSplit) { // Split shape to left and right half |
| 304 |
lo=wt->data[la*(wt->len/128/2)]*15/wt->max; |
| 305 |
ro=wt->data[(ra+128)*(wt->len/128/2)]*15/wt->max; |
| 306 |
} else { |
| 307 |
lo=wt->data[la*wt->len/128]*15/wt->max; |
| 308 |
ro=wt->data[ra*wt->len/128]*15/wt->max; |
| 309 |
} |
| 310 |
if (chan[ch].env.flag.envVinvR) { ro=15-ro; } // vertical invert right envelope |
| 311 |
if (chan[ch].env.flag.envVinvL) { lo=15-lo; } // vertical invert left envelope |
| 312 |
if (lo<0) lo=0; |
| 313 |
if (lo>15) lo=15; |
| 314 |
if (ro<0) ro=0; |
| 315 |
if (ro>15) ro=15; |
| 316 |
envWrite(ch,i,lo,ro); |
| 317 |
} else { |
| 318 |
int out=wt->data[i*wt->len/128]*15/wt->max; |
| 319 |
if (out<0) out=0; |
| 320 |
if (out>15) out=15; |
| 321 |
envWrite(ch,i,out,out); |
| 322 |
} |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
chWrite(ch,5,0x10|(ch&0xf)); |
| 327 |
} else { |
| 328 |
chWrite(ch,1,isMuted[ch]?0:((chan[ch].lvol<<4)|chan[ch].rvol)); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
void DivPlatformX1_010::tick(bool sysTick) { |
| 333 |
for (int i=0; i<16; i++) { |
| 334 |
chan[i].std.next(); |
| 335 |
if (chan[i].std.vol.had) { |
| 336 |
signed char macroVol=((chan[i].vol&15)*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/(chan[i].macroVolMul); |
| 337 |
if ((!isMuted[i]) && (macroVol!=chan[i].outVol)) { |
| 338 |
chan[i].outVol=macroVol; |
| 339 |
chan[i].envChanged=true; |
| 340 |
} |
| 341 |
} |
| 342 |
if ((!chan[i].pcm) || chan[i].furnacePCM) { |
| 343 |
if (NEW_ARP_STRAT) { |
| 344 |
chan[i].handleArp(); |
| 345 |
} else if (chan[i].std.arp.had) { |
| 346 |
if (!chan[i].inPorta) { |
| 347 |
chan[i].baseFreq=NoteX1_010(i,parent->calcArp(chan[i].note,chan[i].std.arp.val)); |
| 348 |
} |
| 349 |
chan[i].freqChanged=true; |
| 350 |
} |
| 351 |
} |
| 352 |
if (chan[i].std.wave.had && !chan[i].pcm) { |
| 353 |
if (chan[i].wave!=chan[i].std.wave.val || chan[i].ws.activeChanged()) { |
| 354 |
chan[i].wave=chan[i].std.wave.val; |
| 355 |
if (!chan[i].pcm) { |
| 356 |
chan[i].ws.changeWave1(chan[i].wave); |
| 357 |
if (!chan[i].keyOff) chan[i].keyOn=true; |
| 358 |
} |
| 359 |
} |
| 360 |
} |
| 361 |
if (chan[i].std.panL.had) { |
| 362 |
chan[i].pan&=0x0f; |
| 363 |
chan[i].pan|=(chan[i].std.panL.val&15)<<4; |
| 364 |
chan[i].envChanged=true; |
| 365 |
} |
| 366 |
if (chan[i].std.panR.had) { |
| 367 |
chan[i].pan&=0xf0; |
| 368 |
chan[i].pan|=chan[i].std.panR.val&15; |
| 369 |
chan[i].envChanged=true; |
| 370 |
} |
| 371 |
if (chan[i].std.pitch.had) { |
| 372 |
if (chan[i].std.pitch.mode) { |
| 373 |
chan[i].pitch2+=chan[i].std.pitch.val; |
| 374 |
CLAMP_VAR(chan[i].pitch2,-65535,65535); |
| 375 |
} else { |
| 376 |
chan[i].pitch2=chan[i].std.pitch.val; |
| 377 |
} |
| 378 |
chan[i].freqChanged=true; |
| 379 |
} |
| 380 |
if (chan[i].std.ex1.had) { |
| 381 |
bool nextEnable=(chan[i].std.ex1.val&1); |
| 382 |
if (nextEnable!=(chan[i].env.flag.envEnable)) { |
| 383 |
chan[i].env.flag.envEnable=nextEnable; |
| 384 |
if (!chan[i].pcm) { |
| 385 |
if (!isMuted[i]) { |
| 386 |
chan[i].envChanged=true; |
| 387 |
} |
| 388 |
refreshControl(i); |
| 389 |
} |
| 390 |
} |
| 391 |
bool nextOneshot=(chan[i].std.ex1.val&2); |
| 392 |
if (nextOneshot!=(chan[i].env.flag.envOneshot)) { |
| 393 |
chan[i].env.flag.envOneshot=nextOneshot; |
| 394 |
if (!chan[i].pcm) { |
| 395 |
refreshControl(i); |
| 396 |
} |
| 397 |
} |
| 398 |
bool nextSplit=(chan[i].std.ex1.val&4); |
| 399 |
if (nextSplit!=(chan[i].env.flag.envSplit)) { |
| 400 |
chan[i].env.flag.envSplit=nextSplit; |
| 401 |
if (!isMuted[i] && !chan[i].pcm) { |
| 402 |
chan[i].envChanged=true; |
| 403 |
} |
| 404 |
} |
| 405 |
bool nextHinvR=(chan[i].std.ex1.val&8); |
| 406 |
if (nextHinvR!=(chan[i].env.flag.envHinvR)) { |
| 407 |
chan[i].env.flag.envHinvR=nextHinvR; |
| 408 |
if (!isMuted[i] && !chan[i].pcm) { |
| 409 |
chan[i].envChanged=true; |
| 410 |
} |
| 411 |
} |
| 412 |
bool nextVinvR=(chan[i].std.ex1.val&16); |
| 413 |
if (nextVinvR!=(chan[i].env.flag.envVinvR)) { |
| 414 |
chan[i].env.flag.envVinvR=nextVinvR; |
| 415 |
if (!isMuted[i] && !chan[i].pcm) { |
| 416 |
chan[i].envChanged=true; |
| 417 |
} |
| 418 |
} |
| 419 |
bool nextHinvL=(chan[i].std.ex1.val&32); |
| 420 |
if (nextHinvL!=(chan[i].env.flag.envHinvL)) { |
| 421 |
chan[i].env.flag.envHinvL=nextHinvL; |
| 422 |
if (!isMuted[i] && !chan[i].pcm) { |
| 423 |
chan[i].envChanged=true; |
| 424 |
} |
| 425 |
} |
| 426 |
bool nextVinvL=(chan[i].std.ex1.val&64); |
| 427 |
if (nextVinvL!=(chan[i].env.flag.envVinvL)) { |
| 428 |
chan[i].env.flag.envVinvL=nextVinvL; |
| 429 |
if (!isMuted[i] && !chan[i].pcm) { |
| 430 |
chan[i].envChanged=true; |
| 431 |
} |
| 432 |
} |
| 433 |
} |
| 434 |
if (chan[i].std.ex2.had) { |
| 435 |
if (chan[i].env.shape!=chan[i].std.ex2.val) { |
| 436 |
chan[i].env.shape=chan[i].std.ex2.val; |
| 437 |
if (!chan[i].pcm) { |
| 438 |
if (chan[i].env.flag.envEnable && (!isMuted[i])) { |
| 439 |
chan[i].envChanged=true; |
| 440 |
} |
| 441 |
if (!chan[i].keyOff) chan[i].keyOn=true; |
| 442 |
} |
| 443 |
} |
| 444 |
} |
| 445 |
if (chan[i].std.ex3.had) { |
| 446 |
chan[i].autoEnvNum=chan[i].std.ex3.val; |
| 447 |
if (!chan[i].pcm) { |
| 448 |
chan[i].freqChanged=true; |
| 449 |
if (!chan[i].std.alg.will) chan[i].autoEnvDen=1; |
| 450 |
} |
| 451 |
} |
| 452 |
if (chan[i].std.alg.had) { |
| 453 |
chan[i].autoEnvDen=chan[i].std.alg.val; |
| 454 |
if (!chan[i].pcm) { |
| 455 |
chan[i].freqChanged=true; |
| 456 |
if (!chan[i].std.ex3.will) chan[i].autoEnvNum=1; |
| 457 |
} |
| 458 |
} |
| 459 |
if (chan[i].std.phaseReset.had) { |
| 460 |
if (chan[i].std.phaseReset.val && chan[i].active && chan[i].pcm) { |
| 461 |
chWrite(i,0,0); |
| 462 |
refreshControl(i); |
| 463 |
} |
| 464 |
} |
| 465 |
if (chan[i].active) { |
| 466 |
if (chan[i].ws.tick()) { |
| 467 |
updateWave(i); |
| 468 |
} |
| 469 |
} |
| 470 |
if (chan[i].envChanged) { |
| 471 |
chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].pan>>4)&0xf))/15); |
| 472 |
chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].pan>>0)&0xf))/15); |
| 473 |
updateEnvelope(i); |
| 474 |
chan[i].envChanged=false; |
| 475 |
} |
| 476 |
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { |
| 477 |
double off=8192.0; |
| 478 |
if (chan[i].pcm) { |
| 479 |
int sample=chan[i].sample; |
| 480 |
if (sample>=0 && sample<parent->song.sampleLen) { |
| 481 |
DivSample* s=parent->getSample(sample); |
| 482 |
if (s->centerRate<1) { |
| 483 |
off=8192.0; |
| 484 |
} else { |
| 485 |
off=8192.0*(s->centerRate/parent->getCenterRate()); |
| 486 |
} |
| 487 |
} |
| 488 |
} |
| 489 |
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,chan[i].pcm?off:CHIP_FREQBASE); |
| 490 |
if (chan[i].fixedFreq) chan[i].freq=chan[i].fixedFreq; |
| 491 |
if (chan[i].pcm) { |
| 492 |
if (chan[i].freq<1) chan[i].freq=1; |
| 493 |
if (chan[i].freq>255) chan[i].freq=255; |
| 494 |
chWrite(i,2,chan[i].freq&0xff); |
| 495 |
} else { |
| 496 |
if (chan[i].freq<0) chan[i].freq=0; |
| 497 |
if (chan[i].freq>65535) chan[i].freq=65535; |
| 498 |
chWrite(i,2,chan[i].freq&0xff); |
| 499 |
chWrite(i,3,(chan[i].freq>>8)&0xff); |
| 500 |
if (chan[i].freqChanged && chan[i].autoEnvNum>0 && chan[i].autoEnvDen>0) { |
| 501 |
chan[i].env.period=(chan[i].freq*chan[i].autoEnvDen/chan[i].autoEnvNum)>>12; |
| 502 |
chWrite(i,4,chan[i].env.period); |
| 503 |
} |
| 504 |
} |
| 505 |
if (chan[i].keyOn || chan[i].keyOff || (chRead(i,0)&1)) { |
| 506 |
refreshControl(i); |
| 507 |
} |
| 508 |
if (chan[i].keyOn) chan[i].keyOn=false; |
| 509 |
if (chan[i].keyOff) chan[i].keyOff=false; |
| 510 |
chan[i].freqChanged=false; |
| 511 |
} |
| 512 |
if (sysTick) { |
| 513 |
if (chan[i].env.slide!=0) { |
| 514 |
chan[i].env.slidefrac+=chan[i].env.slide; |
| 515 |
while (chan[i].env.slidefrac>0xf) { |
| 516 |
chan[i].env.slidefrac-=0x10; |
| 517 |
if (chan[i].env.period<0xff) { |
| 518 |
chan[i].env.period++; |
| 519 |
if (!chan[i].pcm) { |
| 520 |
chWrite(i,4,chan[i].env.period); |
| 521 |
} |
| 522 |
} |
| 523 |
} |
| 524 |
while (chan[i].env.slidefrac<-0xf) { |
| 525 |
chan[i].env.slidefrac+=0x10; |
| 526 |
if (chan[i].env.period>0) { |
| 527 |
chan[i].env.period--; |
| 528 |
if (!chan[i].pcm) { |
| 529 |
chWrite(i,4,chan[i].env.period); |
| 530 |
} |
| 531 |
} |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
int DivPlatformX1_010::dispatch(DivCommand c) { |
| 539 |
switch (c.cmd) { |
| 540 |
case DIV_CMD_NOTE_ON: { |
| 541 |
chWrite(c.chan,0,0); // reset previous note |
| 542 |
DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_X1_010); |
| 543 |
chan[c.chan].macroVolMul=ins->type==DIV_INS_AMIGA?64:15; |
| 544 |
if ((ins->type==DIV_INS_AMIGA || ins->amiga.useSample) || chan[c.chan].pcm) { |
| 545 |
if (ins->type==DIV_INS_AMIGA || ins->amiga.useSample) { |
| 546 |
chan[c.chan].furnacePCM=true; |
| 547 |
chan[c.chan].pcm=true; |
| 548 |
} else { |
| 549 |
chan[c.chan].furnacePCM=false; |
| 550 |
chan[c.chan].pcm=false; |
| 551 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 552 |
chan[c.chan].sampleNoteDelta=0; |
| 553 |
chWrite(c.chan,0,0); // reset |
| 554 |
chWrite(c.chan,1,0); |
| 555 |
chWrite(c.chan,2,0); |
| 556 |
chWrite(c.chan,4,0); |
| 557 |
chWrite(c.chan,5,0); |
| 558 |
updateWave(c.chan); |
| 559 |
} |
| 560 |
} |
| 561 |
if (chan[c.chan].pcm) { |
| 562 |
if (skipRegisterWrites) break; |
| 563 |
if (chan[c.chan].furnacePCM) { |
| 564 |
chan[c.chan].pcm=true; |
| 565 |
chan[c.chan].macroInit(ins); |
| 566 |
if (c.value!=DIV_NOTE_NULL) { |
| 567 |
chan[c.chan].sample=ins->amiga.getSample(c.value); |
| 568 |
chan[c.chan].sampleNote=c.value; |
| 569 |
c.value=ins->amiga.getFreq(c.value); |
| 570 |
chan[c.chan].sampleNoteDelta=c.value-chan[c.chan].sampleNote; |
| 571 |
} |
| 572 |
if (chan[c.chan].sample>=0 && chan[c.chan].sample<parent->song.sampleLen) { |
| 573 |
DivSample* s=parent->getSample(chan[c.chan].sample); |
| 574 |
if (isBanked) { |
| 575 |
chan[c.chan].bankSlot=ins->x1_010.bankSlot; |
| 576 |
bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17; |
| 577 |
unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff); |
| 578 |
chWrite(c.chan,4,(bankedOffs>>12)&0xff); |
| 579 |
int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded |
| 580 |
chWrite(c.chan,5,(0x100-(end>>12))&0xff); |
| 581 |
} else { |
| 582 |
chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff); |
| 583 |
int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded |
| 584 |
chWrite(c.chan,5,(0x100-(end>>12))&0xff); |
| 585 |
} |
| 586 |
if (c.value!=DIV_NOTE_NULL) { |
| 587 |
chan[c.chan].note=c.value; |
| 588 |
chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note); |
| 589 |
chan[c.chan].fixedFreq=0; |
| 590 |
chan[c.chan].freqChanged=true; |
| 591 |
} |
| 592 |
} else { |
| 593 |
chan[c.chan].macroInit(NULL); |
| 594 |
chan[c.chan].outVol=chan[c.chan].vol; |
| 595 |
// huh? |
| 596 |
if ((12*sampleBank+c.value%12)>=parent->song.sampleLen) { |
| 597 |
chWrite(c.chan,0,0); // reset |
| 598 |
chWrite(c.chan,1,0); |
| 599 |
chWrite(c.chan,2,0); |
| 600 |
chWrite(c.chan,4,0); |
| 601 |
chWrite(c.chan,5,0); |
| 602 |
break; |
| 603 |
} |
| 604 |
} |
| 605 |
} else { |
| 606 |
chan[c.chan].macroInit(NULL); |
| 607 |
chan[c.chan].outVol=chan[c.chan].vol; |
| 608 |
chan[c.chan].sample=12*sampleBank+c.value%12; |
| 609 |
if (chan[c.chan].sample<0 || chan[c.chan].sample>=parent->song.sampleLen) { |
| 610 |
chWrite(c.chan,0,0); // reset |
| 611 |
chWrite(c.chan,1,0); |
| 612 |
chWrite(c.chan,2,0); |
| 613 |
chWrite(c.chan,4,0); |
| 614 |
chWrite(c.chan,5,0); |
| 615 |
break; |
| 616 |
} |
| 617 |
DivSample* s=parent->getSample(chan[c.chan].sample); |
| 618 |
if (isBanked) { |
| 619 |
bankSlot[chan[c.chan].bankSlot]=sampleOffX1[chan[c.chan].sample]>>17; |
| 620 |
unsigned int bankedOffs=(chan[c.chan].bankSlot<<17)|(sampleOffX1[chan[c.chan].sample]&0x1ffff); |
| 621 |
chWrite(c.chan,4,(bankedOffs>>12)&0xff); |
| 622 |
int end=(bankedOffs+MIN(s->length8,0x1ffff)+0xfff)&~0xfff; // padded |
| 623 |
chWrite(c.chan,5,(0x100-(end>>12))&0xff); |
| 624 |
} else { |
| 625 |
chWrite(c.chan,4,(sampleOffX1[chan[c.chan].sample]>>12)&0xff); |
| 626 |
int end=(sampleOffX1[chan[c.chan].sample]+s->length8+0xfff)&~0xfff; // padded |
| 627 |
chWrite(c.chan,5,(0x100-(end>>12))&0xff); |
| 628 |
} |
| 629 |
// ???? |
| 630 |
chan[c.chan].fixedFreq=(((unsigned int)s->rate)<<4)/(chipClock/512); |
| 631 |
chan[c.chan].freqChanged=true; |
| 632 |
} |
| 633 |
} else if (c.value!=DIV_NOTE_NULL) { |
| 634 |
chan[c.chan].note=c.value; |
| 635 |
chan[c.chan].sampleNote=DIV_NOTE_NULL; |
| 636 |
chan[c.chan].sampleNoteDelta=0; |
| 637 |
chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note); |
| 638 |
chan[c.chan].fixedFreq=0; |
| 639 |
chan[c.chan].freqChanged=true; |
| 640 |
} |
| 641 |
chan[c.chan].active=true; |
| 642 |
chan[c.chan].keyOn=true; |
| 643 |
chan[c.chan].envChanged=true; |
| 644 |
chan[c.chan].macroInit(ins); |
| 645 |
if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { |
| 646 |
chan[c.chan].outVol=chan[c.chan].vol; |
| 647 |
} |
| 648 |
if (chan[c.chan].wave<0) { |
| 649 |
chan[c.chan].wave=0; |
| 650 |
chan[c.chan].ws.changeWave1(chan[c.chan].wave); |
| 651 |
} |
| 652 |
chan[c.chan].ws.init(ins,128,255,chan[c.chan].insChanged); |
| 653 |
chan[c.chan].insChanged=false; |
| 654 |
refreshControl(c.chan); |
| 655 |
break; |
| 656 |
} |
| 657 |
case DIV_CMD_NOTE_OFF: |
| 658 |
chan[c.chan].pcm=false; |
| 659 |
chan[c.chan].active=false; |
| 660 |
chan[c.chan].keyOff=true; |
| 661 |
chan[c.chan].macroInit(NULL); |
| 662 |
break; |
| 663 |
case DIV_CMD_NOTE_OFF_ENV: |
| 664 |
case DIV_CMD_ENV_RELEASE: |
| 665 |
chan[c.chan].std.release(); |
| 666 |
break; |
| 667 |
case DIV_CMD_INSTRUMENT: |
| 668 |
if (chan[c.chan].ins!=c.value || c.value2==1) { |
| 669 |
chan[c.chan].ins=c.value; |
| 670 |
chan[c.chan].insChanged=true; |
| 671 |
} |
| 672 |
break; |
| 673 |
case DIV_CMD_VOLUME: |
| 674 |
if (chan[c.chan].vol!=c.value) { |
| 675 |
chan[c.chan].vol=c.value; |
| 676 |
if (!chan[c.chan].std.vol.has) { |
| 677 |
if (chan[c.chan].outVol!=c.value) { |
| 678 |
chan[c.chan].outVol=c.value; |
| 679 |
if (!isMuted[c.chan]) { |
| 680 |
chan[c.chan].envChanged=true; |
| 681 |
} |
| 682 |
} |
| 683 |
} |
| 684 |
} |
| 685 |
break; |
| 686 |
case DIV_CMD_GET_VOLUME: |
| 687 |
if (chan[c.chan].std.vol.has) { |
| 688 |
return chan[c.chan].vol; |
| 689 |
} |
| 690 |
return chan[c.chan].outVol; |
| 691 |
break; |
| 692 |
case DIV_CMD_PITCH: |
| 693 |
chan[c.chan].pitch=c.value; |
| 694 |
chan[c.chan].freqChanged=true; |
| 695 |
break; |
| 696 |
case DIV_CMD_WAVE: |
| 697 |
chan[c.chan].wave=c.value; |
| 698 |
chan[c.chan].ws.changeWave1(chan[c.chan].wave); |
| 699 |
chan[c.chan].keyOn=true; |
| 700 |
break; |
| 701 |
case DIV_CMD_X1_010_ENVELOPE_SHAPE: |
| 702 |
if (chan[c.chan].env.shape!=c.value) { |
| 703 |
chan[c.chan].env.shape=c.value; |
| 704 |
if (!chan[c.chan].pcm) { |
| 705 |
if (chan[c.chan].env.flag.envEnable && (!isMuted[c.chan])) { |
| 706 |
chan[c.chan].envChanged=true; |
| 707 |
} |
| 708 |
chan[c.chan].keyOn=true; |
| 709 |
} |
| 710 |
} |
| 711 |
break; |
| 712 |
case DIV_CMD_NOTE_PORTA: { |
| 713 |
int destFreq=NoteX1_010(c.chan,c.value2+chan[c.chan].sampleNoteDelta); |
| 714 |
bool return2=false; |
| 715 |
if (destFreq>chan[c.chan].baseFreq) { |
| 716 |
chan[c.chan].baseFreq+=c.value; |
| 717 |
if (chan[c.chan].baseFreq>=destFreq) { |
| 718 |
chan[c.chan].baseFreq=destFreq; |
| 719 |
return2=true; |
| 720 |
} |
| 721 |
} else { |
| 722 |
chan[c.chan].baseFreq-=c.value; |
| 723 |
if (chan[c.chan].baseFreq<=destFreq) { |
| 724 |
chan[c.chan].baseFreq=destFreq; |
| 725 |
return2=true; |
| 726 |
} |
| 727 |
} |
| 728 |
chan[c.chan].freqChanged=true; |
| 729 |
if (return2) { |
| 730 |
chan[c.chan].inPorta=false; |
| 731 |
return 2; |
| 732 |
} |
| 733 |
break; |
| 734 |
} |
| 735 |
case DIV_CMD_SAMPLE_MODE: |
| 736 |
if (chan[c.chan].pcm!=(c.value&1)) { |
| 737 |
chan[c.chan].pcm=c.value&1; |
| 738 |
chan[c.chan].freqChanged=true; |
| 739 |
chan[c.chan].envChanged=true; |
| 740 |
} |
| 741 |
break; |
| 742 |
case DIV_CMD_SAMPLE_BANK: |
| 743 |
sampleBank=c.value; |
| 744 |
if (sampleBank>(parent->song.sample.size()/12)) { |
| 745 |
sampleBank=parent->song.sample.size()/12; |
| 746 |
} |
| 747 |
break; |
| 748 |
case DIV_CMD_PANNING: { |
| 749 |
if (!stereo) break; |
| 750 |
unsigned char newPan=(c.value&0xf0)|(c.value2>>4); |
| 751 |
if (chan[c.chan].pan!=newPan) { |
| 752 |
chan[c.chan].pan=newPan; |
| 753 |
if (!isMuted[c.chan]) { |
| 754 |
chan[c.chan].envChanged=true; |
| 755 |
} |
| 756 |
} |
| 757 |
break; |
| 758 |
} |
| 759 |
case DIV_CMD_LEGATO: |
| 760 |
chan[c.chan].note=c.value; |
| 761 |
chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note+chan[c.chan].sampleNoteDelta+((HACKY_LEGATO_MESS)?(chan[c.chan].std.arp.val):(0))); |
| 762 |
chan[c.chan].freqChanged=true; |
| 763 |
break; |
| 764 |
case DIV_CMD_PRE_PORTA: |
| 765 |
if (chan[c.chan].active && c.value2) { |
| 766 |
if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_X1_010)); |
| 767 |
} |
| 768 |
if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will && !NEW_ARP_STRAT) chan[c.chan].baseFreq=NoteX1_010(c.chan,chan[c.chan].note); |
| 769 |
chan[c.chan].inPorta=c.value; |
| 770 |
break; |
| 771 |
case DIV_CMD_SAMPLE_FREQ: |
| 772 |
if (chan[c.chan].pcm) { |
| 773 |
chan[c.chan].freq=MAX(1,c.value&0xff); |
| 774 |
chWrite(c.chan,2,chan[c.chan].freq&0xff); |
| 775 |
if (chRead(c.chan,0)&1) { |
| 776 |
refreshControl(c.chan); |
| 777 |
} |
| 778 |
} |
| 779 |
break; |
| 780 |
case DIV_CMD_X1_010_ENVELOPE_MODE: { |
| 781 |
bool nextEnable=c.value&1; |
| 782 |
if (nextEnable!=(chan[c.chan].env.flag.envEnable)) { |
| 783 |
chan[c.chan].env.flag.envEnable=nextEnable; |
| 784 |
if (!chan[c.chan].pcm) { |
| 785 |
if (!isMuted[c.chan]) { |
| 786 |
chan[c.chan].envChanged=true; |
| 787 |
} |
| 788 |
refreshControl(c.chan); |
| 789 |
} |
| 790 |
} |
| 791 |
bool nextOneshot=c.value&2; |
| 792 |
if (nextOneshot!=(chan[c.chan].env.flag.envOneshot)) { |
| 793 |
chan[c.chan].env.flag.envOneshot=nextOneshot; |
| 794 |
if (!chan[c.chan].pcm) { |
| 795 |
refreshControl(c.chan); |
| 796 |
} |
| 797 |
} |
| 798 |
bool nextSplit=c.value&4; |
| 799 |
if (nextSplit!=(chan[c.chan].env.flag.envSplit)) { |
| 800 |
chan[c.chan].env.flag.envSplit=nextSplit; |
| 801 |
if (!isMuted[c.chan] && !chan[c.chan].pcm) { |
| 802 |
chan[c.chan].envChanged=true; |
| 803 |
} |
| 804 |
} |
| 805 |
bool nextHinvR=c.value&8; |
| 806 |
if (nextHinvR!=(chan[c.chan].env.flag.envHinvR)) { |
| 807 |
chan[c.chan].env.flag.envHinvR=nextHinvR; |
| 808 |
if (!isMuted[c.chan] && !chan[c.chan].pcm) { |
| 809 |
chan[c.chan].envChanged=true; |
| 810 |
} |
| 811 |
} |
| 812 |
bool nextVinvR=c.value&16; |
| 813 |
if (nextVinvR!=(chan[c.chan].env.flag.envVinvR)) { |
| 814 |
chan[c.chan].env.flag.envVinvR=nextVinvR; |
| 815 |
if (!isMuted[c.chan] && !chan[c.chan].pcm) { |
| 816 |
chan[c.chan].envChanged=true; |
| 817 |
} |
| 818 |
} |
| 819 |
bool nextHinvL=c.value&32; |
| 820 |
if (nextHinvL!=(chan[c.chan].env.flag.envHinvL)) { |
| 821 |
chan[c.chan].env.flag.envHinvL=nextHinvL; |
| 822 |
if (!isMuted[c.chan] && !chan[c.chan].pcm) { |
| 823 |
chan[c.chan].envChanged=true; |
| 824 |
} |
| 825 |
} |
| 826 |
bool nextVinvL=c.value&64; |
| 827 |
if (nextVinvL!=(chan[c.chan].env.flag.envVinvL)) { |
| 828 |
chan[c.chan].env.flag.envVinvL=nextVinvL; |
| 829 |
if (!isMuted[c.chan] && !chan[c.chan].pcm) { |
| 830 |
chan[c.chan].envChanged=true; |
| 831 |
} |
| 832 |
} |
| 833 |
break; |
| 834 |
} |
| 835 |
case DIV_CMD_X1_010_ENVELOPE_PERIOD: |
| 836 |
chan[c.chan].env.period=c.value; |
| 837 |
if (!chan[c.chan].pcm) { |
| 838 |
chWrite(c.chan,4,chan[c.chan].env.period); |
| 839 |
} |
| 840 |
break; |
| 841 |
case DIV_CMD_X1_010_ENVELOPE_SLIDE: |
| 842 |
chan[c.chan].env.slide=c.value; |
| 843 |
break; |
| 844 |
case DIV_CMD_X1_010_AUTO_ENVELOPE: |
| 845 |
chan[c.chan].autoEnvNum=c.value>>4; |
| 846 |
chan[c.chan].autoEnvDen=c.value&15; |
| 847 |
chan[c.chan].freqChanged=true; |
| 848 |
break; |
| 849 |
case DIV_CMD_X1_010_SAMPLE_BANK_SLOT: |
| 850 |
chan[c.chan].bankSlot=c.value&7; |
| 851 |
break; |
| 852 |
case DIV_CMD_GET_VOLMAX: |
| 853 |
return 15; |
| 854 |
break; |
| 855 |
case DIV_CMD_MACRO_OFF: |
| 856 |
chan[c.chan].std.mask(c.value,true); |
| 857 |
break; |
| 858 |
case DIV_CMD_MACRO_ON: |
| 859 |
chan[c.chan].std.mask(c.value,false); |
| 860 |
break; |
| 861 |
case DIV_CMD_MACRO_RESTART: |
| 862 |
chan[c.chan].std.restart(c.value); |
| 863 |
break; |
| 864 |
default: |
| 865 |
break; |
| 866 |
} |
| 867 |
return 1; |
| 868 |
} |
| 869 |
|
| 870 |
void DivPlatformX1_010::muteChannel(int ch, bool mute) { |
| 871 |
isMuted[ch]=mute; |
| 872 |
chan[ch].envChanged=true; |
| 873 |
} |
| 874 |
|
| 875 |
void DivPlatformX1_010::forceIns() { |
| 876 |
for (int i=0; i<16; i++) { |
| 877 |
chan[i].insChanged=true; |
| 878 |
chan[i].envChanged=true; |
| 879 |
chan[i].freqChanged=true; |
| 880 |
updateWave(i); |
| 881 |
} |
| 882 |
} |
| 883 |
|
| 884 |
void* DivPlatformX1_010::getChanState(int ch) { |
| 885 |
return &chan[ch]; |
| 886 |
} |
| 887 |
|
| 888 |
DivMacroInt* DivPlatformX1_010::getChanMacroInt(int ch) { |
| 889 |
return &chan[ch].std; |
| 890 |
} |
| 891 |
|
| 892 |
unsigned short DivPlatformX1_010::getPan(int ch) { |
| 893 |
if (!stereo) return 0; |
| 894 |
return ((chan[ch].pan&0xf0)<<4)|(chan[ch].pan&15); |
| 895 |
} |
| 896 |
|
| 897 |
DivDispatchOscBuffer* DivPlatformX1_010::getOscBuffer(int ch) { |
| 898 |
return oscBuf[ch]; |
| 899 |
} |
| 900 |
|
| 901 |
unsigned char* DivPlatformX1_010::getRegisterPool() { |
| 902 |
for (int i=0; i<0x2000; i++) { |
| 903 |
regPool[i]=x1_010.ram_r(i); |
| 904 |
} |
| 905 |
return regPool; |
| 906 |
} |
| 907 |
|
| 908 |
int DivPlatformX1_010::getRegisterPoolSize() { |
| 909 |
return 0x2000; |
| 910 |
} |
| 911 |
|
| 912 |
void DivPlatformX1_010::reset() { |
| 913 |
memset(regPool,0,0x2000); |
| 914 |
for (int i=0; i<16; i++) { |
| 915 |
chan[i]=DivPlatformX1_010::Channel(); |
| 916 |
chan[i].reset(); |
| 917 |
chan[i].std.setEngine(parent); |
| 918 |
chan[i].ws.setEngine(parent); |
| 919 |
chan[i].ws.init(NULL,128,255,false); |
| 920 |
} |
| 921 |
x1_010.reset(); |
| 922 |
sampleBank=0; |
| 923 |
// set per-channel initial panning |
| 924 |
for (int i=0; i<16; i++) { |
| 925 |
chWrite(i,0,0); |
| 926 |
} |
| 927 |
// set initial bank |
| 928 |
for (int b=0; b<8; b++) { |
| 929 |
bankSlot[b]=b; |
| 930 |
} |
| 931 |
} |
| 932 |
|
| 933 |
int DivPlatformX1_010::getOutputCount() { |
| 934 |
return stereo?2:1; |
| 935 |
} |
| 936 |
|
| 937 |
bool DivPlatformX1_010::keyOffAffectsArp(int ch) { |
| 938 |
return true; |
| 939 |
} |
| 940 |
|
| 941 |
float DivPlatformX1_010::getPostAmp() { |
| 942 |
return 4.0f; |
| 943 |
} |
| 944 |
|
| 945 |
void DivPlatformX1_010::notifyWaveChange(int wave) { |
| 946 |
for (int i=0; i<16; i++) { |
| 947 |
if (chan[i].wave==wave) { |
| 948 |
chan[i].ws.changeWave1(wave); |
| 949 |
updateWave(i); |
| 950 |
} |
| 951 |
} |
| 952 |
} |
| 953 |
|
| 954 |
void DivPlatformX1_010::notifyInsDeletion(void* ins) { |
| 955 |
for (int i=0; i<16; i++) { |
| 956 |
chan[i].std.notifyInsDeletion((DivInstrument*)ins); |
| 957 |
} |
| 958 |
} |
| 959 |
|
| 960 |
void DivPlatformX1_010::setFlags(const DivConfig& flags) { |
| 961 |
switch (flags.getInt("clockSel",0)) { |
| 962 |
case 1: // 16.67MHz (later hardwares) |
| 963 |
chipClock=50000000.0/3.0; |
| 964 |
break; |
| 965 |
case 2: // 14.32MHz (see https://github.com/mamedev/mame/blob/master/src/mame/taito/champbwl.cpp#L620) |
| 966 |
chipClock=COLOR_NTSC*4.0; |
| 967 |
break; |
| 968 |
// Other clock is used |
| 969 |
default: // 16MHz (earlier hardwares) |
| 970 |
chipClock=16000000; |
| 971 |
break; |
| 972 |
} |
| 973 |
CHECK_CUSTOM_CLOCK; |
| 974 |
rate=chipClock/512; |
| 975 |
stereo=flags.getBool("stereo",false); |
| 976 |
isBanked=flags.getBool("isBanked",false); |
| 977 |
for (int i=0; i<16; i++) { |
| 978 |
oscBuf[i]->setRate(rate); |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
void DivPlatformX1_010::poke(unsigned int addr, unsigned short val) { |
| 983 |
rWrite(addr,val); |
| 984 |
} |
| 985 |
|
| 986 |
void DivPlatformX1_010::poke(std::vector<DivRegWrite>& wlist) { |
| 987 |
for (DivRegWrite& i: wlist) rWrite(i.addr,i.val); |
| 988 |
} |
| 989 |
|
| 990 |
const void* DivPlatformX1_010::getSampleMem(int index) { |
| 991 |
return index >= 0 ? sampleMem : 0; |
| 992 |
} |
| 993 |
|
| 994 |
size_t DivPlatformX1_010::getSampleMemCapacity(int index) { |
| 995 |
return index == 0 ? (isBanked?16777216:1048576):0; |
| 996 |
} |
| 997 |
|
| 998 |
size_t DivPlatformX1_010::getSampleMemUsage(int index) { |
| 999 |
return index >= 0 ? sampleMemLen : 0; |
| 1000 |
} |
| 1001 |
|
| 1002 |
bool DivPlatformX1_010::isSampleLoaded(int index, int sample) { |
| 1003 |
if (index!=0) return false; |
| 1004 |
if (sample<0 || sample>32767) return false; |
| 1005 |
return sampleLoaded[sample]; |
| 1006 |
} |
| 1007 |
|
| 1008 |
const DivMemoryComposition* DivPlatformX1_010::getMemCompo(int index) { |
| 1009 |
if (index!=0) return NULL; |
| 1010 |
return &memCompo; |
| 1011 |
} |
| 1012 |
|
| 1013 |
void DivPlatformX1_010::renderSamples(int sysID) { |
| 1014 |
memset(sampleMem,0,16777216); |
| 1015 |
memset(sampleOffX1,0,32768*sizeof(unsigned int)); |
| 1016 |
memset(sampleLoaded,0,32768*sizeof(bool)); |
| 1017 |
|
| 1018 |
memCompo=DivMemoryComposition(); |
| 1019 |
memCompo.name="Sample ROM"; |
| 1020 |
|
| 1021 |
size_t memPos=0; |
| 1022 |
for (int i=0; i<parent->song.sampleLen; i++) { |
| 1023 |
DivSample* s=parent->song.sample[i]; |
| 1024 |
if (!s->renderOn[0][sysID]) { |
| 1025 |
sampleOffX1[i]=0; |
| 1026 |
continue; |
| 1027 |
} |
| 1028 |
|
| 1029 |
int paddedLen=(s->length8+4095)&(~0xfff); |
| 1030 |
if (isBanked) { |
| 1031 |
// fit sample bank size to 128KB for Seta 2 external bankswitching logic (not emulated yet!) |
| 1032 |
if (paddedLen>131072) { |
| 1033 |
paddedLen=131072; |
| 1034 |
} |
| 1035 |
if ((memPos&0xfe0000)!=((memPos+paddedLen)&0xfe0000)) { |
| 1036 |
memPos=(memPos+0x1ffff)&0xfe0000; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
if (memPos>=getSampleMemCapacity()) { |
| 1040 |
logW("out of X1-010 memory for sample %d!",i); |
| 1041 |
break; |
| 1042 |
} |
| 1043 |
if (memPos+paddedLen>=getSampleMemCapacity()) { |
| 1044 |
memcpy(sampleMem+memPos,s->data8,getSampleMemCapacity()-memPos); |
| 1045 |
logW("out of X1-010 memory for sample %d!",i); |
| 1046 |
} else { |
| 1047 |
memcpy(sampleMem+memPos,s->data8,paddedLen); |
| 1048 |
sampleLoaded[i]=true; |
| 1049 |
} |
| 1050 |
sampleOffX1[i]=memPos; |
| 1051 |
memCompo.entries.push_back(DivMemoryEntry(DIV_MEMORY_SAMPLE,"Sample",i,memPos,memPos+paddedLen)); |
| 1052 |
memPos+=paddedLen; |
| 1053 |
} |
| 1054 |
sampleMemLen=memPos+256; |
| 1055 |
|
| 1056 |
memCompo.used=sampleMemLen; |
| 1057 |
memCompo.capacity=getSampleMemCapacity(0); |
| 1058 |
} |
| 1059 |
|
| 1060 |
int DivPlatformX1_010::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { |
| 1061 |
parent=p; |
| 1062 |
dumpWrites=false; |
| 1063 |
skipRegisterWrites=false; |
| 1064 |
stereo=false; |
| 1065 |
for (int i=0; i<16; i++) { |
| 1066 |
isMuted[i]=false; |
| 1067 |
oscBuf[i]=new DivDispatchOscBuffer; |
| 1068 |
} |
| 1069 |
setFlags(flags); |
| 1070 |
sampleMem=new unsigned char[16777216]; |
| 1071 |
sampleMemLen=0; |
| 1072 |
x1_010.reset(); |
| 1073 |
reset(); |
| 1074 |
return 16; |
| 1075 |
} |
| 1076 |
|
| 1077 |
void DivPlatformX1_010::quit() { |
| 1078 |
for (int i=0; i<16; i++) { |
| 1079 |
delete oscBuf[i]; |
| 1080 |
} |
| 1081 |
delete[] sampleMem; |
| 1082 |
} |
| 1083 |
|
| 1084 |
// initialization of important arrays |
| 1085 |
DivPlatformX1_010::DivPlatformX1_010(): |
| 1086 |
DivDispatch(), |
| 1087 |
vgsound_emu_mem_intf(), |
| 1088 |
x1_010(*this) { |
| 1089 |
sampleOffX1=new unsigned int[32768]; |
| 1090 |
sampleLoaded=new bool[32768]; |
| 1091 |
} |
| 1092 |
|
| 1093 |
DivPlatformX1_010::~DivPlatformX1_010() { |
| 1094 |
delete[] sampleOffX1; |
| 1095 |
delete[] sampleLoaded; |
| 1096 |
} |