mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-22 04:25:11 +00:00
dev213 - Merge pull request #1954 from akumanatt/snesveratia
SNES, VERA and TIA additions
This commit is contained in:
commit
54e9a31971
23 changed files with 884 additions and 37 deletions
|
@ -708,6 +708,7 @@ src/engine/wavOps.cpp
|
|||
src/engine/vgmOps.cpp
|
||||
src/engine/zsmOps.cpp
|
||||
src/engine/zsm.cpp
|
||||
src/engine/tiunaOps.cpp
|
||||
|
||||
src/engine/platform/abstract.cpp
|
||||
src/engine/platform/genesis.cpp
|
||||
|
|
|
@ -586,6 +586,7 @@ size | description
|
|||
| - 0: BRR emphasis
|
||||
1 | flags 2 (>=159) or reserved
|
||||
| - 0: dither
|
||||
| - 1: no BRR filters (>=213)
|
||||
4 | loop start
|
||||
| - -1 means no loop
|
||||
4 | loop end
|
||||
|
|
|
@ -138,7 +138,7 @@ void brrEncodeBlock(const short* buf, unsigned char* out, unsigned char range, u
|
|||
}
|
||||
}
|
||||
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis) {
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis, unsigned char noFilter) {
|
||||
if (len==0) return 0;
|
||||
|
||||
// encoding process:
|
||||
|
@ -157,6 +157,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigne
|
|||
long total=0;
|
||||
unsigned char filter=0;
|
||||
unsigned char range=0;
|
||||
unsigned char numFilters=noFilter?2:4;
|
||||
|
||||
short x0=0;
|
||||
short x1=0;
|
||||
|
@ -211,7 +212,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigne
|
|||
}
|
||||
|
||||
// encode
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int j=0; j<numFilters; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
brrEncodeBlock(in,possibleOut[j][k],k,j,&last1[j][k],&last2[j][k],&avgError[j][k]);
|
||||
}
|
||||
|
@ -228,7 +229,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigne
|
|||
}
|
||||
}
|
||||
} else {
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int j=0; j<numFilters; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
if (avgError[j][k]<candError) {
|
||||
candError=avgError[j][k];
|
||||
|
@ -245,7 +246,7 @@ long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigne
|
|||
out[j+1]=possibleOut[filter][range][j];
|
||||
}
|
||||
|
||||
for (int j=0; j<4; j++) {
|
||||
for (int j=0; j<numFilters; j++) {
|
||||
for (int k=0; k<13; k++) {
|
||||
last1[j][k]=last1[filter][range];
|
||||
last2[j][k]=last2[filter][range];
|
||||
|
|
|
@ -34,9 +34,10 @@ extern "C" {
|
|||
* @param len input length (should be a multiple of 16. if it isn't, the output will be padded).
|
||||
* @param loopStart beginning of loop area (may be -1 for no loop). this is used to ensure the respective block has no filter in order to loop properly.
|
||||
* @param emphasis apply filter to compensate for Gaussian interpolation high frequency loss.
|
||||
* @param noFilter do not use filters in any block. this is used to allow seeking to any sample position.
|
||||
* @return number of written samples.
|
||||
*/
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis);
|
||||
long brrEncode(short* buf, unsigned char* out, long len, long loopStart, unsigned char emphasis, unsigned char noFilter);
|
||||
|
||||
/**
|
||||
* read len bytes from buf, decode BRR and output to out.
|
||||
|
|
|
@ -54,8 +54,8 @@ class DivWorkPool;
|
|||
|
||||
//#define DIV_UNSTABLE
|
||||
|
||||
#define DIV_VERSION "0.6.4"
|
||||
#define DIV_ENGINE_VERSION 212
|
||||
#define DIV_VERSION "dev213"
|
||||
#define DIV_ENGINE_VERSION 213
|
||||
// for imports
|
||||
#define DIV_VERSION_MOD 0xff01
|
||||
#define DIV_VERSION_FC 0xff02
|
||||
|
@ -703,6 +703,8 @@ class DivEngine {
|
|||
SafeWriter* saveVGM(bool* sysToExport=NULL, bool loop=true, int version=0x171, bool patternHints=false, bool directStream=false, int trailingTicks=-1);
|
||||
// dump to ZSM.
|
||||
SafeWriter* saveZSM(unsigned int zsmrate=60, bool loop=true, bool optimize=true);
|
||||
// dump to TIunA.
|
||||
SafeWriter* saveTiuna(const bool* sysToExport, const char* baseLabel, int firstBankSize, int otherBankSize);
|
||||
// dump command stream.
|
||||
SafeWriter* saveCommand();
|
||||
// export to text
|
||||
|
|
|
@ -2083,6 +2083,19 @@ bool DivEngine::loadFur(unsigned char* file, size_t len, int variantID) {
|
|||
}
|
||||
}
|
||||
|
||||
// VERA old chip revision
|
||||
// TIA old tuning
|
||||
if (ds.version<213) {
|
||||
for (int i=0; i<ds.systemLen; i++) {
|
||||
if (ds.system[i]==DIV_SYSTEM_VERA) {
|
||||
ds.systemFlags[i].set("chipType",0);
|
||||
}
|
||||
if (ds.system[i]==DIV_SYSTEM_TIA) {
|
||||
ds.systemFlags[i].set("oldPitch",true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (active) quitDispatch();
|
||||
BUSY_BEGIN_SOFT;
|
||||
saveLock.lock();
|
||||
|
|
|
@ -261,6 +261,7 @@ SafeWriter* DivEngine::saveText(bool separatePatterns) {
|
|||
w->writeText(fmt::sprintf(" - mode: %s\n",sampleLoopModes[sample->loopMode&3]));
|
||||
}
|
||||
w->writeText(fmt::sprintf("- BRR emphasis: %s\n",trueFalse[sample->brrEmphasis?1:0]));
|
||||
w->writeText(fmt::sprintf("- no BRR filters: %s\n",trueFalse[sample->brrNoFilter?1:0]));
|
||||
w->writeText(fmt::sprintf("- dither: %s\n",trueFalse[sample->dither?1:0]));
|
||||
|
||||
// TODO' render matrix
|
||||
|
|
|
@ -221,7 +221,7 @@ void DivPlatformSNES::tick(bool sysTick) {
|
|||
end=MIN(start+MAX(s->lengthBRR+((s->loop && s->depth!=DIV_SAMPLE_DEPTH_BRR)?9:0),1),getSampleMemCapacity());
|
||||
loop=MAX(start,end-1);
|
||||
if (chan[i].audPos>0) {
|
||||
start=start+MIN(chan[i].audPos,s->lengthBRR-1)/16*9;
|
||||
start=start+MIN(chan[i].audPos/16*9,end-start);
|
||||
}
|
||||
if (s->isLoopable()) {
|
||||
loop=((s->depth!=DIV_SAMPLE_DEPTH_BRR)?9:0)+start+((s->loopStart/16)*9);
|
||||
|
@ -463,7 +463,6 @@ int DivPlatformSNES::dispatch(DivCommand c) {
|
|||
chan[c.chan].inPorta=c.value;
|
||||
break;
|
||||
case DIV_CMD_SAMPLE_POS:
|
||||
// may have to remove this
|
||||
chan[c.chan].audPos=c.value;
|
||||
chan[c.chan].setPos=true;
|
||||
break;
|
||||
|
@ -933,7 +932,6 @@ const void* DivPlatformSNES::getSampleMem(int index) {
|
|||
}
|
||||
|
||||
size_t DivPlatformSNES::getSampleMemCapacity(int index) {
|
||||
// TODO change it based on current echo buffer size
|
||||
return index == 0 ? (65536-echoDelay*2048) : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
// Copyright (c) 2020 Frank van den Hoef
|
||||
// All rights reserved. License: 2-clause BSD
|
||||
|
||||
// Chip revisions
|
||||
// 0: V 0.3.0
|
||||
// 1: V 47.0.0 (9-bit volume, phase reset on mute)
|
||||
|
||||
#include "vera_psg.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
@ -14,7 +18,15 @@ enum waveform {
|
|||
WF_NOISE,
|
||||
};
|
||||
|
||||
static uint8_t volume_lut[64] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31, 33, 35, 37, 39, 42, 44, 47, 50, 52, 56, 59, 63};
|
||||
static uint16_t volume_lut[64] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31, 33, 35, 37, 39, 42, 44, 47, 50, 52, 56, 59, 63};
|
||||
static uint16_t volume_lut_47[64] = {
|
||||
0, 4, 8, 12,
|
||||
16, 17, 18, 20, 21, 22, 23, 25, 26, 28, 30, 31,
|
||||
33, 35, 37, 40, 42, 45, 47, 50, 53, 56, 60, 63,
|
||||
67, 71, 75, 80, 85, 90, 95, 101, 107, 113, 120, 127,
|
||||
135, 143, 151, 160, 170, 180, 191, 202, 214, 227, 241, 255,
|
||||
270, 286, 303, 321, 341, 361, 382, 405, 429, 455, 482, 511
|
||||
};
|
||||
|
||||
void
|
||||
psg_reset(struct VERA_PSG* psg)
|
||||
|
@ -38,7 +50,7 @@ psg_writereg(struct VERA_PSG* psg, uint8_t reg, uint8_t val)
|
|||
case 2: {
|
||||
psg->channels[ch].right = (val & 0x80) != 0;
|
||||
psg->channels[ch].left = (val & 0x40) != 0;
|
||||
psg->channels[ch].volume = volume_lut[val & 0x3F];
|
||||
psg->channels[ch].volume = ((psg->chipType < 1) ? volume_lut : volume_lut_47)[val & 0x3F];
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
|
@ -65,8 +77,11 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right)
|
|||
struct VERAChannel *ch = &psg->channels[i];
|
||||
|
||||
unsigned new_phase = (ch->phase + ch->freq) & 0x1FFFF;
|
||||
if ((psg->chipType >= 1) && (!ch->left && !ch->right)) {
|
||||
new_phase = 0;
|
||||
}
|
||||
if ((ch->phase & 0x10000) != (new_phase & 0x10000)) {
|
||||
ch->noiseval = psg->noiseOut;
|
||||
ch->noiseval = (psg->chipType < 1) ? psg->noiseOut : (psg->noiseState >> 1) & 0x3f;
|
||||
}
|
||||
ch->phase = new_phase;
|
||||
|
||||
|
@ -85,14 +100,14 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right)
|
|||
int val = (int)sv * (int)ch->volume;
|
||||
|
||||
if (ch->left) {
|
||||
l += val;
|
||||
l += (psg->chipType < 1) ? val : val >> 3;
|
||||
}
|
||||
if (ch->right) {
|
||||
r += val;
|
||||
r += (psg->chipType < 1) ? val : val >> 3;
|
||||
}
|
||||
|
||||
if (ch->left || ch->right) {
|
||||
ch->lastOut = val;
|
||||
ch->lastOut = (psg->chipType < 1) ? val << 3 : val;
|
||||
} else {
|
||||
ch->lastOut = 0;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
struct VERAChannel {
|
||||
uint16_t freq;
|
||||
uint8_t volume;
|
||||
uint16_t volume;
|
||||
bool left, right;
|
||||
uint8_t pw;
|
||||
uint8_t waveform;
|
||||
|
@ -20,7 +20,7 @@ struct VERAChannel {
|
|||
};
|
||||
|
||||
struct VERA_PSG {
|
||||
unsigned int noiseState, noiseOut;
|
||||
unsigned int chipType, noiseState, noiseOut;
|
||||
struct VERAChannel channels[16];
|
||||
};
|
||||
|
||||
|
|
|
@ -40,6 +40,30 @@ const char** DivPlatformTIA::getRegisterSheet() {
|
|||
|
||||
void DivPlatformTIA::acquire(short** buf, size_t len) {
|
||||
for (size_t h=0; h<len; h++) {
|
||||
if (softwarePitch) {
|
||||
int i=-1;
|
||||
tuneCounter++;
|
||||
if (tuneCounter==228) {
|
||||
i=0;
|
||||
}
|
||||
if (tuneCounter>=456) {
|
||||
i=1;
|
||||
tuneCounter=0;
|
||||
}
|
||||
if (i>=0) {
|
||||
if (chan[i].tuneCtr++>=chan[i].curFreq) {
|
||||
int freq=chan[i].freq;
|
||||
chan[i].tuneAcc+=chan[i].tuneFreq;
|
||||
if (chan[i].tuneAcc>=256) {
|
||||
freq++;
|
||||
chan[i].tuneAcc-=256;
|
||||
}
|
||||
chan[i].curFreq=freq;
|
||||
chan[i].tuneCtr=0;
|
||||
rWrite(0x17+i,freq);
|
||||
}
|
||||
}
|
||||
}
|
||||
tia.tick();
|
||||
if (mixingType==2) {
|
||||
buf[0][h]=tia.myCurrentSample[0];
|
||||
|
@ -92,6 +116,44 @@ unsigned char DivPlatformTIA::dealWithFreq(unsigned char shape, int base, int pi
|
|||
return ret;
|
||||
}
|
||||
|
||||
int DivPlatformTIA::dealWithFreqNew(int shape, int bp) {
|
||||
double mult=(parent->song.tuning*0.0625)*pow(2.0,double(768+bp)/(256.0*12.0));
|
||||
double clock=chipClock/28.5;
|
||||
switch (shape) {
|
||||
case 1: // buzzy
|
||||
mult*=30;
|
||||
break;
|
||||
case 2: // low buzzy
|
||||
mult*=465;
|
||||
break;
|
||||
case 3: // flangy
|
||||
mult*=58.125;
|
||||
break;
|
||||
case 4: case 5: // square
|
||||
mult*=4;
|
||||
break;
|
||||
case 6: case 7: case 9: case 10: // pure buzzy/reedy
|
||||
mult*=62;
|
||||
break;
|
||||
case 8: // noise
|
||||
mult*=63.875;
|
||||
break;
|
||||
case 12: case 13: // low square
|
||||
mult*=12;
|
||||
break;
|
||||
case 14: case 15: // low pure buzzy/reedy
|
||||
mult*=186;
|
||||
break;
|
||||
}
|
||||
if (mult<1) mult=1;
|
||||
if (clock<mult) {
|
||||
return 0;
|
||||
}
|
||||
double ret=floor(clock/mult);
|
||||
int fract=((clock/mult)-ret)*256;
|
||||
return ret*256+fract-256;
|
||||
}
|
||||
|
||||
void DivPlatformTIA::tick(bool sysTick) {
|
||||
for (int i=0; i<2; i++) {
|
||||
chan[i].std.next();
|
||||
|
@ -120,13 +182,17 @@ void DivPlatformTIA::tick(bool sysTick) {
|
|||
chan[i].freqChanged=true;
|
||||
}
|
||||
if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) {
|
||||
int bf=chan[i].baseFreq;
|
||||
if (!chan[i].fixedArp) {
|
||||
bf+=chan[i].arpOff<<8;
|
||||
}
|
||||
if (chan[i].fixedArp) {
|
||||
chan[i].freq=chan[i].baseNoteOverride&31;
|
||||
} else {
|
||||
chan[i].tuneFreq=0;
|
||||
if (!skipRegisterWrites && dumpWrites) {
|
||||
addWrite(0xfffe0000+i,chan[i].freq*256);
|
||||
}
|
||||
} else if (oldPitch) {
|
||||
int bf=chan[i].baseFreq;
|
||||
if (!chan[i].fixedArp) {
|
||||
bf+=chan[i].arpOff<<8;
|
||||
}
|
||||
chan[i].freq=dealWithFreq(chan[i].shape,bf,chan[i].pitch+chan[i].pitch2);
|
||||
if (chan[i].shape==4 || chan[i].shape==5) {
|
||||
if (bf<39*256) {
|
||||
|
@ -140,12 +206,41 @@ void DivPlatformTIA::tick(bool sysTick) {
|
|||
}
|
||||
}
|
||||
if (chan[i].freq>31) chan[i].freq=31;
|
||||
chan[i].tuneFreq=0;
|
||||
} else {
|
||||
int bf=chan[i].baseFreq+(chan[i].arpOff<<8);
|
||||
int shape=chan[i].shape;
|
||||
if (shape==4 || shape==5) {
|
||||
if (bf<40*256) {
|
||||
shape=6;
|
||||
rWrite(0x15+i,6);
|
||||
} else if (bf<59*256) {
|
||||
shape=12;
|
||||
rWrite(0x15+i,12);
|
||||
} else {
|
||||
rWrite(0x15+i,4);
|
||||
}
|
||||
}
|
||||
bf+=chan[i].pitch+chan[i].pitch2;
|
||||
int freq=dealWithFreqNew(shape,bf);
|
||||
if (freq>=31*256) freq=31*256;
|
||||
if (softwarePitch && !skipRegisterWrites && dumpWrites) {
|
||||
addWrite(0xfffe0000+i,freq);
|
||||
}
|
||||
chan[i].freq=freq>>8;
|
||||
chan[i].tuneFreq=freq&255;
|
||||
}
|
||||
|
||||
if (chan[i].keyOff) {
|
||||
rWrite(0x19+i,0);
|
||||
}
|
||||
rWrite(0x17+i,chan[i].freq);
|
||||
if (!softwarePitch) {
|
||||
if (chan[i].tuneFreq>=128) chan[i].freq++;
|
||||
rWrite(0x17+i,chan[i].freq);
|
||||
if (!skipRegisterWrites && dumpWrites) {
|
||||
addWrite(0xfffe0000+i,chan[i].freq<<8);
|
||||
}
|
||||
}
|
||||
if (chan[i].keyOn) chan[i].keyOn=false;
|
||||
if (chan[i].keyOff) chan[i].keyOff=false;
|
||||
chan[i].freqChanged=false;
|
||||
|
@ -272,6 +367,11 @@ int DivPlatformTIA::dispatch(DivCommand c) {
|
|||
break;
|
||||
case DIV_CMD_PRE_NOTE:
|
||||
break;
|
||||
case DIV_CMD_EXTERNAL:
|
||||
if (!skipRegisterWrites && dumpWrites) {
|
||||
addWrite(0xfffe0002,c.value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
//printf("WARNING: unimplemented command %d\n",c.cmd);
|
||||
break;
|
||||
|
@ -319,6 +419,7 @@ int DivPlatformTIA::getRegisterPoolSize() {
|
|||
}
|
||||
|
||||
void DivPlatformTIA::reset() {
|
||||
tuneCounter=0;
|
||||
tia.reset(mixingType);
|
||||
memset(regPool,0,16);
|
||||
for (int i=0; i<2; i++) {
|
||||
|
@ -367,6 +468,8 @@ void DivPlatformTIA::setFlags(const DivConfig& flags) {
|
|||
CHECK_CUSTOM_CLOCK;
|
||||
rate=chipClock;
|
||||
mixingType=flags.getInt("mixingType",0)&3;
|
||||
softwarePitch=flags.getBool("softwarePitch",false);
|
||||
oldPitch=flags.getBool("oldPitch",false);
|
||||
for (int i=0; i<2; i++) {
|
||||
oscBuf[i]->rate=rate/114;
|
||||
}
|
||||
|
|
|
@ -27,21 +27,31 @@ class DivPlatformTIA: public DivDispatch {
|
|||
protected:
|
||||
struct Channel: public SharedChannel<int> {
|
||||
unsigned char shape;
|
||||
unsigned char curFreq, tuneCtr, tuneFreq;
|
||||
int tuneAcc;
|
||||
Channel():
|
||||
SharedChannel<int>(15),
|
||||
shape(4) {}
|
||||
shape(4),
|
||||
curFreq(0),
|
||||
tuneCtr(0),
|
||||
tuneFreq(0),
|
||||
tuneAcc(0) {}
|
||||
};
|
||||
Channel chan[2];
|
||||
DivDispatchOscBuffer* oscBuf[2];
|
||||
bool isMuted[2];
|
||||
bool softwarePitch;
|
||||
bool oldPitch;
|
||||
unsigned char mixingType;
|
||||
unsigned char chanOscCounter;
|
||||
TIA::Audio tia;
|
||||
unsigned char regPool[16];
|
||||
int tuneCounter;
|
||||
friend void putDispatchChip(void*,int);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
|
||||
unsigned char dealWithFreq(unsigned char shape, int base, int pitch);
|
||||
int dealWithFreqNew(int shape, int bp);
|
||||
|
||||
public:
|
||||
void acquire(short** buf, size_t len);
|
||||
|
|
|
@ -119,7 +119,7 @@ void DivPlatformVERA::acquire(short** buf, size_t len) {
|
|||
pos++;
|
||||
|
||||
for (int i=0; i<16; i++) {
|
||||
oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut<<3;
|
||||
oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut;
|
||||
}
|
||||
int pcmOut=(whyCallItBuf[2][i]+whyCallItBuf[3][i])>>1;
|
||||
if (pcmOut<-32768) pcmOut=-32768;
|
||||
|
@ -532,6 +532,7 @@ void DivPlatformVERA::poke(std::vector<DivRegWrite>& wlist) {
|
|||
}
|
||||
|
||||
void DivPlatformVERA::setFlags(const DivConfig& flags) {
|
||||
psg->chipType=flags.getInt("chipType",1);
|
||||
chipClock=25000000;
|
||||
CHECK_CUSTOM_CLOCK;
|
||||
rate=chipClock/512;
|
||||
|
|
|
@ -56,7 +56,7 @@ void DivSample::putSampleData(SafeWriter* w) {
|
|||
w->writeC(depth);
|
||||
w->writeC(loopMode);
|
||||
w->writeC(brrEmphasis);
|
||||
w->writeC(dither);
|
||||
w->writeC((dither?1:0)|(brrNoFilter?2:0));
|
||||
w->writeI(loop?loopStart:-1);
|
||||
w->writeI(loop?loopEnd:-1);
|
||||
|
||||
|
@ -134,7 +134,9 @@ DivDataErrors DivSample::readSampleData(SafeReader& reader, short version) {
|
|||
reader.readC();
|
||||
}
|
||||
if (version>=159) {
|
||||
dither=reader.readC()&1;
|
||||
signed char c=reader.readC();
|
||||
dither=c&1;
|
||||
if (version>=213) brrNoFilter=c&2;
|
||||
} else {
|
||||
reader.readC();
|
||||
}
|
||||
|
@ -1423,7 +1425,7 @@ void DivSample::render(unsigned int formatMask) {
|
|||
if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_BRR)) { // BRR
|
||||
int sampleCount=loop?loopEnd:samples;
|
||||
if (!initInternal(DIV_SAMPLE_DEPTH_BRR,sampleCount)) return;
|
||||
brrEncode(data16,dataBRR,sampleCount,loop?loopStart:-1,brrEmphasis);
|
||||
brrEncode(data16,dataBRR,sampleCount,loop?loopStart:-1,brrEmphasis,brrNoFilter);
|
||||
}
|
||||
if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_VOX)) { // VOX
|
||||
if (!initInternal(DIV_SAMPLE_DEPTH_VOX,samples)) return;
|
||||
|
@ -1564,9 +1566,9 @@ DivSampleHistory* DivSample::prepareUndo(bool data, bool doNotPush) {
|
|||
duplicate=new unsigned char[getCurBufLen()];
|
||||
memcpy(duplicate,getCurBuf(),getCurBufLen());
|
||||
}
|
||||
h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,dither,loopMode);
|
||||
h=new DivSampleHistory(duplicate,getCurBufLen(),samples,depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,brrNoFilter,dither,loopMode);
|
||||
} else {
|
||||
h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,dither,loopMode);
|
||||
h=new DivSampleHistory(depth,rate,centerRate,loopStart,loopEnd,loop,brrEmphasis,brrNoFilter,dither,loopMode);
|
||||
}
|
||||
if (!doNotPush) {
|
||||
while (!redoHist.empty()) {
|
||||
|
@ -1600,6 +1602,7 @@ DivSampleHistory* DivSample::prepareUndo(bool data, bool doNotPush) {
|
|||
loopEnd=h->loopEnd; \
|
||||
loop=h->loop; \
|
||||
brrEmphasis=h->brrEmphasis; \
|
||||
brrNoFilter=h->brrNoFilter; \
|
||||
dither=h->dither; \
|
||||
loopMode=h->loopMode;
|
||||
|
||||
|
|
|
@ -65,10 +65,10 @@ struct DivSampleHistory {
|
|||
unsigned int length, samples;
|
||||
DivSampleDepth depth;
|
||||
int rate, centerRate, loopStart, loopEnd;
|
||||
bool loop, brrEmphasis, dither;
|
||||
bool loop, brrEmphasis, brrNoFilter, dither;
|
||||
DivSampleLoopMode loopMode;
|
||||
bool hasSample;
|
||||
DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool di, DivSampleLoopMode lm):
|
||||
DivSampleHistory(void* d, unsigned int l, unsigned int s, DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool bf, bool di, DivSampleLoopMode lm):
|
||||
data((unsigned char*)d),
|
||||
length(l),
|
||||
samples(s),
|
||||
|
@ -79,10 +79,11 @@ struct DivSampleHistory {
|
|||
loopEnd(le),
|
||||
loop(lp),
|
||||
brrEmphasis(be),
|
||||
brrNoFilter(bf),
|
||||
dither(di),
|
||||
loopMode(lm),
|
||||
hasSample(true) {}
|
||||
DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool di, DivSampleLoopMode lm):
|
||||
DivSampleHistory(DivSampleDepth de, int r, int cr, int ls, int le, bool lp, bool be, bool bf, bool di, DivSampleLoopMode lm):
|
||||
data(NULL),
|
||||
length(0),
|
||||
samples(0),
|
||||
|
@ -93,6 +94,7 @@ struct DivSampleHistory {
|
|||
loopEnd(le),
|
||||
loop(lp),
|
||||
brrEmphasis(be),
|
||||
brrNoFilter(bf),
|
||||
dither(di),
|
||||
loopMode(lm),
|
||||
hasSample(false) {}
|
||||
|
@ -118,7 +120,7 @@ struct DivSample {
|
|||
// - 13: IMA ADPCM
|
||||
// - 16: 16-bit PCM
|
||||
DivSampleDepth depth;
|
||||
bool loop, brrEmphasis, dither;
|
||||
bool loop, brrEmphasis, brrNoFilter, dither;
|
||||
// valid values are:
|
||||
// - 0: Forward loop
|
||||
// - 1: Backward loop
|
||||
|
@ -337,6 +339,7 @@ struct DivSample {
|
|||
depth(DIV_SAMPLE_DEPTH_16BIT),
|
||||
loop(false),
|
||||
brrEmphasis(true),
|
||||
brrNoFilter(false),
|
||||
dither(false),
|
||||
loopMode(DIV_SAMPLE_LOOP_FORWARD),
|
||||
data8(NULL),
|
||||
|
|
518
src/engine/tiunaOps.cpp
Normal file
518
src/engine/tiunaOps.cpp
Normal file
|
@ -0,0 +1,518 @@
|
|||
/**
|
||||
* Furnace Tracker - multi-system chiptune tracker
|
||||
* Copyright (C) 2021-2024 tildearrow and contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include "engine.h"
|
||||
#include "../fileutils.h"
|
||||
#include "../ta-log.h"
|
||||
|
||||
struct TiunaNew {
|
||||
short pitch=-1;
|
||||
signed char ins=-1;
|
||||
signed char vol=-1;
|
||||
short sync=-1;
|
||||
};
|
||||
struct TiunaLast {
|
||||
short pitch=0;
|
||||
signed char ins=0;
|
||||
signed char vol=0;
|
||||
int tick=1;
|
||||
bool forcePitch=true;
|
||||
};
|
||||
struct TiunaCmd {
|
||||
signed char pitchChange=-1;
|
||||
short pitchSet=-1;
|
||||
signed char ins=-1;
|
||||
signed char vol=-1;
|
||||
short sync=-1;
|
||||
short wait=-1;
|
||||
};
|
||||
struct TiunaBytes {
|
||||
unsigned char ch=0;
|
||||
int ticks=0;
|
||||
unsigned char size=0;
|
||||
unsigned char buf[16];
|
||||
friend bool operator==(const TiunaBytes& l, const TiunaBytes& r) {
|
||||
if (l.size!=r.size) return false;
|
||||
if (l.ticks!=r.ticks) return false;
|
||||
return memcmp(l.buf,r.buf,l.size)==0;
|
||||
}
|
||||
};
|
||||
struct TiunaMatch {
|
||||
int pos;
|
||||
int endPos;
|
||||
int size;
|
||||
int id;
|
||||
};
|
||||
struct TiunaMatches {
|
||||
int bytesSaved=INT32_MIN;
|
||||
int length=0;
|
||||
int ticks=0;
|
||||
std::vector<int> pos;
|
||||
};
|
||||
|
||||
static void writeCmd(std::vector<TiunaBytes>& cmds, TiunaCmd& cmd, unsigned char ch, int& lastWait, int fromTick, int toTick) {
|
||||
while (fromTick<toTick) {
|
||||
int val=MIN(toTick-fromTick,256);
|
||||
if (lastWait!=val) {
|
||||
cmd.wait=val;
|
||||
lastWait=val;
|
||||
}
|
||||
TiunaBytes nbuf;
|
||||
unsigned char vcw1=0x80;
|
||||
unsigned char vcw2=0;
|
||||
unsigned char vcwLen=0;
|
||||
unsigned char nlen=0;
|
||||
nbuf.ch=ch;
|
||||
nbuf.ticks=val;
|
||||
if (cmd.sync>=0) {
|
||||
nbuf.buf[nlen++]=0b00111100;
|
||||
nbuf.buf[nlen++]=cmd.sync;
|
||||
}
|
||||
if (cmd.wait>=17) {
|
||||
nbuf.buf[nlen++]=0b00111111;
|
||||
nbuf.buf[nlen++]=cmd.wait-1;
|
||||
}
|
||||
if (cmd.pitchChange>=0) {
|
||||
nbuf.buf[nlen++]=0b01000000|cmd.pitchChange;
|
||||
}
|
||||
if (cmd.pitchSet>=0) {
|
||||
nbuf.buf[nlen++]=0b01100000|(cmd.pitchSet>>8);
|
||||
nbuf.buf[nlen++]=cmd.pitchSet&0xff;
|
||||
}
|
||||
if (cmd.vol>=1) {
|
||||
vcw1|=0x40|cmd.vol;
|
||||
vcwLen++;
|
||||
}
|
||||
if (cmd.ins>=0) {
|
||||
vcw1|=0x20;
|
||||
if (vcwLen==0) vcw1|=cmd.ins;
|
||||
else vcw2=cmd.ins;
|
||||
vcwLen++;
|
||||
}
|
||||
if (cmd.wait>=1 && cmd.wait<17) {
|
||||
unsigned char val=cmd.wait-1;
|
||||
vcw1|=0x10;
|
||||
if (vcwLen==0) vcw1|=val;
|
||||
else if (vcwLen==1) vcw2=val;
|
||||
else vcw2|=(val<<4);
|
||||
vcwLen++;
|
||||
}
|
||||
nbuf.buf[nlen++]=vcw1;
|
||||
if (vcwLen>=2) nbuf.buf[nlen++]=vcw2;
|
||||
nbuf.size=nlen;
|
||||
cmds.push_back(nbuf);
|
||||
cmd=TiunaCmd();
|
||||
fromTick+=val;
|
||||
}
|
||||
}
|
||||
|
||||
SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel, int firstBankSize, int otherBankSize) {
|
||||
stop();
|
||||
repeatPattern=false;
|
||||
shallStop=false;
|
||||
setOrder(0);
|
||||
BUSY_BEGIN_SOFT;
|
||||
// determine loop point
|
||||
// bool stopped=false;
|
||||
int loopOrder=0;
|
||||
int loopOrderRow=0;
|
||||
int loopEnd=0;
|
||||
walkSong(loopOrder,loopOrderRow,loopEnd);
|
||||
logI("loop point: %d %d",loopOrder,loopOrderRow);
|
||||
|
||||
SafeWriter* w=new SafeWriter;
|
||||
w->init();
|
||||
|
||||
int tiaIdx=-1;
|
||||
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
if (sysToExport!=NULL && !sysToExport[i]) continue;
|
||||
if (song.system[i]==DIV_SYSTEM_TIA) {
|
||||
tiaIdx=i;
|
||||
disCont[i].dispatch->toggleRegisterDump(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tiaIdx<0) {
|
||||
lastError="selected TIA system not found";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// write patterns
|
||||
// bool writeLoop=false;
|
||||
bool done=false;
|
||||
playSub(false);
|
||||
|
||||
int tick=0;
|
||||
// int loopTick=-1;
|
||||
TiunaLast last[2];
|
||||
TiunaNew news[2];
|
||||
std::map<int,TiunaCmd> allCmds[2];
|
||||
while (!done) {
|
||||
// TODO implement loop
|
||||
// if (loopTick<0 && loopOrder==curOrder && loopOrderRow==curRow
|
||||
// && (ticks-((tempoAccum+virtualTempoN)/virtualTempoD))<=0
|
||||
// ) {
|
||||
// writeLoop=true;
|
||||
// loopTick=tick;
|
||||
// // invalidate last register state so it always force an absolute write after loop
|
||||
// for (int i=0; i<2; i++) {
|
||||
// last[i]=TiunaLast();
|
||||
// last[i].pitch=-1;
|
||||
// last[i].ins=-1;
|
||||
// last[i].vol=-1;
|
||||
// }
|
||||
// }
|
||||
if (nextTick(false,true) || !playing) {
|
||||
// stopped=!playing;
|
||||
done=true;
|
||||
break;
|
||||
}
|
||||
for (int i=0; i<2; i++) {
|
||||
news[i]=TiunaNew();
|
||||
}
|
||||
// get register dumps
|
||||
std::vector<DivRegWrite>& writes=disCont[tiaIdx].dispatch->getRegisterWrites();
|
||||
for (const DivRegWrite& i: writes) {
|
||||
switch (i.addr) {
|
||||
case 0xfffe0000:
|
||||
case 0xfffe0001:
|
||||
news[i.addr&1].pitch=i.val;
|
||||
break;
|
||||
case 0xfffe0002:
|
||||
news[0].sync=i.val;
|
||||
break;
|
||||
case 0x15:
|
||||
case 0x16:
|
||||
news[i.addr-0x15].ins=i.val;
|
||||
break;
|
||||
case 0x19:
|
||||
case 0x1a:
|
||||
news[i.addr-0x19].vol=i.val;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
writes.clear();
|
||||
// collect changes
|
||||
for (int i=0; i<2; i++) {
|
||||
TiunaCmd cmds;
|
||||
bool hasCmd=false;
|
||||
if (news[i].pitch>=0 && (last[i].forcePitch || news[i].pitch!=last[i].pitch)) {
|
||||
int dt=news[i].pitch-last[i].pitch;
|
||||
if (!last[i].forcePitch && abs(dt)<=16) {
|
||||
if (dt<0) cmds.pitchChange=15-dt;
|
||||
else cmds.pitchChange=dt-1;
|
||||
}
|
||||
else cmds.pitchSet=news[i].pitch;
|
||||
last[i].pitch=news[i].pitch;
|
||||
last[i].forcePitch=false;
|
||||
hasCmd=true;
|
||||
}
|
||||
if (news[i].ins>=0 && news[i].ins!=last[i].ins) {
|
||||
cmds.ins=news[i].ins;
|
||||
last[i].ins=news[i].ins;
|
||||
hasCmd=true;
|
||||
}
|
||||
if (news[i].vol>=0 && news[i].vol!=last[i].vol) {
|
||||
cmds.vol=(news[i].vol-last[i].vol)&0xf;
|
||||
last[i].vol=news[i].vol;
|
||||
hasCmd=true;
|
||||
}
|
||||
if (news[i].sync>=0) {
|
||||
cmds.sync=news[i].sync;
|
||||
hasCmd=true;
|
||||
}
|
||||
if (hasCmd) allCmds[i][tick]=cmds;
|
||||
}
|
||||
cmdStream.clear();
|
||||
tick++;
|
||||
}
|
||||
for (int i=0; i<song.systemLen; i++) {
|
||||
disCont[i].dispatch->getRegisterWrites().clear();
|
||||
disCont[i].dispatch->toggleRegisterDump(false);
|
||||
}
|
||||
|
||||
remainingLoops=-1;
|
||||
playing=false;
|
||||
freelance=false;
|
||||
extValuePresent=false;
|
||||
BUSY_END;
|
||||
|
||||
// render commands
|
||||
std::vector<TiunaBytes> renderedCmds;
|
||||
w->writeText(fmt::format(
|
||||
"; Generated by Furnace " DIV_VERSION "\n"
|
||||
"; Name: {}\n"
|
||||
"; Author: {}\n"
|
||||
"; Album: {}\n"
|
||||
"; Subsong #{}: {}\n\n",
|
||||
song.name,song.author,song.category,curSubSongIndex+1,curSubSong->name
|
||||
));
|
||||
for (int i=0; i<2; i++) {
|
||||
TiunaCmd lastCmd;
|
||||
int lastTick=0;
|
||||
int lastWait=0;
|
||||
// bool looped=false;
|
||||
for (auto& kv: allCmds[i]) {
|
||||
// if (!looped && !stopped && loopTick>=0 && kv.first>=loopTick) {
|
||||
// writeCmd(w,&lastCmd,&lastWait,loopTick-lastTick);
|
||||
// w->writeText(".loop\n");
|
||||
// lastTick=loopTick;
|
||||
// looped=true;
|
||||
// }
|
||||
writeCmd(renderedCmds,lastCmd,i,lastWait,lastTick,kv.first);
|
||||
lastTick=kv.first;
|
||||
lastCmd=kv.second;
|
||||
}
|
||||
writeCmd(renderedCmds,lastCmd,i,lastWait,lastTick,tick);
|
||||
// if (stopped || loopTick<0) w->writeText(".loop\n db 0\n");
|
||||
}
|
||||
// compress commands
|
||||
std::vector<TiunaMatch> confirmedMatches;
|
||||
std::vector<int> callTicks;
|
||||
int cmId=0;
|
||||
int cmdSize=renderedCmds.size();
|
||||
std::vector<bool> processed=std::vector<bool>(cmdSize,false);
|
||||
while (firstBankSize>768 && cmId<(MAX(firstBankSize/1024,1))*256) {
|
||||
std::map<int,TiunaMatches> potentialMatches;
|
||||
for (int i=0; i<cmdSize-1;) {
|
||||
// continue and skip if it's part of previous confirmed matches
|
||||
while (i<cmdSize-1 && processed[i]) i++;
|
||||
if (i>=cmdSize-1) break;
|
||||
std::vector<TiunaMatch> match;
|
||||
int ch=renderedCmds[i].ch;
|
||||
for (int j=i+1; j<cmdSize;) {
|
||||
while (j<cmdSize && processed[i]) j++;
|
||||
if (j>=cmdSize) break;
|
||||
int k=0;
|
||||
int ticks=0;
|
||||
int size=0;
|
||||
while (
|
||||
(i+k)<j && (i+k)<cmdSize && (j+k)<cmdSize &&
|
||||
(ticks+renderedCmds[i+k].ticks)<=256 &&
|
||||
// match runs can't cross channels
|
||||
// as channel end command would be insterted there later
|
||||
renderedCmds[i+k].ch==ch &&
|
||||
renderedCmds[j+k].ch==ch &&
|
||||
renderedCmds[i+k]==renderedCmds[j+k] &&
|
||||
!processed[i+k] && !processed[j+k]
|
||||
) {
|
||||
ticks+=renderedCmds[i+k].ticks;
|
||||
size+=renderedCmds[i+k].size;
|
||||
k++;
|
||||
}
|
||||
if (size>2) match.push_back({j,j+k,size,0});
|
||||
if (k==0) k++;
|
||||
j+=k;
|
||||
}
|
||||
if (match.empty()) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
// find a length that results in most bytes saved
|
||||
TiunaMatches matches;
|
||||
int curSize=0;
|
||||
int curLength=1;
|
||||
int curTicks=0;
|
||||
while (true) {
|
||||
int bytesSaved=-4;
|
||||
bool found=false;
|
||||
for (const TiunaMatch& j: match) {
|
||||
if ((j.endPos-j.pos)>=curLength) {
|
||||
if (!found) {
|
||||
found=true;
|
||||
curSize+=renderedCmds[i+curLength-1].size;
|
||||
curTicks+=renderedCmds[i+curLength-1].ticks;
|
||||
}
|
||||
bytesSaved+=curSize-2;
|
||||
}
|
||||
}
|
||||
if (!found) break;
|
||||
if (bytesSaved>matches.bytesSaved) {
|
||||
matches.length=curLength;
|
||||
matches.bytesSaved=bytesSaved;
|
||||
matches.ticks=curTicks;
|
||||
}
|
||||
curLength++;
|
||||
}
|
||||
if (matches.bytesSaved>0) {
|
||||
matches.pos.push_back(i);
|
||||
for (const TiunaMatch& j: match) {
|
||||
if ((j.endPos-j.pos)>=matches.length) {
|
||||
matches.pos.push_back(j.pos);
|
||||
}
|
||||
}
|
||||
potentialMatches[i]=matches;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (potentialMatches.empty()) break;
|
||||
int maxPMIdx=0;
|
||||
int maxPMVal=0;
|
||||
for (const auto& i: potentialMatches) {
|
||||
if (i.second.bytesSaved>maxPMVal) {
|
||||
maxPMVal=i.second.bytesSaved;
|
||||
maxPMIdx=i.first;
|
||||
}
|
||||
}
|
||||
int maxPMLen=potentialMatches[maxPMIdx].length;
|
||||
for (const int i: potentialMatches[maxPMIdx].pos) {
|
||||
confirmedMatches.push_back({i,i+maxPMLen,0,cmId});
|
||||
std::fill(processed.begin()+i,processed.begin()+(i+maxPMLen),true);
|
||||
}
|
||||
callTicks.push_back(potentialMatches[maxPMIdx].ticks);
|
||||
logI("CM %04x added: pos=%d,len=%d,matches=%d,saved=%d",cmId,maxPMIdx,maxPMLen,potentialMatches[maxPMIdx].pos.size(),maxPMVal);
|
||||
cmId++;
|
||||
}
|
||||
std::sort(confirmedMatches.begin(),confirmedMatches.end(),[](const TiunaMatch& l, const TiunaMatch& r){
|
||||
return l.pos<r.pos;
|
||||
});
|
||||
// ignore last call IDs >256 that don't fill up a page
|
||||
// as they tends to increase the final size due to page alignment
|
||||
int cmIdLen=cmId>256?(cmId&~255):cmId;
|
||||
// overlap check
|
||||
for (int i=1; i<(int)confirmedMatches.size(); i++) {
|
||||
if (confirmedMatches[i-1].endPos<=confirmedMatches[i].pos) continue;
|
||||
lastError="impossible overlap found in matches list, please report";
|
||||
return NULL;
|
||||
}
|
||||
SafeWriter dbg;
|
||||
dbg.init();
|
||||
dbg.writeText(fmt::format("renderedCmds size={}\n",renderedCmds.size()));
|
||||
for (const auto& i: confirmedMatches) {
|
||||
dbg.writeText(fmt::format("pos={},end={},id={}\n",i.pos,i.endPos,i.id,i.size));
|
||||
}
|
||||
|
||||
// write commands
|
||||
int totalSize=0;
|
||||
int cnt=cmIdLen;
|
||||
w->writeText(fmt::format(" .section {0}_bank0\n .align $100\n{0}_calltable",baseLabel));
|
||||
while (cnt>0) {
|
||||
int cnt2=MIN(cnt,256);
|
||||
w->writeText("\n .byte ");
|
||||
for (int j=0; j<cnt2; j++) {
|
||||
w->writeText(fmt::format("<{}_c{},",baseLabel,cmIdLen-cnt+j));
|
||||
}
|
||||
for (int j=cnt2; j<256; j++) {
|
||||
w->writeText("0,");
|
||||
}
|
||||
w->seek(-1,SEEK_CUR);
|
||||
w->writeText("\n .byte ");
|
||||
for (int j=0; j<cnt2; j++) {
|
||||
w->writeText(fmt::format(">{}_c{},",baseLabel,cmIdLen-cnt+j));
|
||||
}
|
||||
for (int j=cnt2; j<256; j++) {
|
||||
w->writeText("0,");
|
||||
}
|
||||
w->seek(-1,SEEK_CUR);
|
||||
w->writeText("\n .byte ");
|
||||
for (int j=0; j<cnt2; j++) {
|
||||
w->writeText(fmt::format("{}_c{}>>13,",baseLabel,cmIdLen-cnt+j));
|
||||
}
|
||||
for (int j=cnt2; j<256; j++) {
|
||||
w->writeText("0,");
|
||||
}
|
||||
w->seek(-1,SEEK_CUR);
|
||||
w->writeText("\n .byte ");
|
||||
for (int j=0; j<cnt2; j++) {
|
||||
w->writeText(fmt::format("{},",callTicks[cmIdLen-cnt+j]&0xff));
|
||||
}
|
||||
w->seek(-1,SEEK_CUR);
|
||||
totalSize+=768+cnt2;
|
||||
cnt-=cnt2;
|
||||
}
|
||||
w->writeC('\n');
|
||||
if (totalSize>firstBankSize) {
|
||||
lastError="first bank is not large enough to contain call table";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int curBank=0;
|
||||
int bankSize=totalSize;
|
||||
int maxBankSize=firstBankSize;
|
||||
int curCh=-1;
|
||||
std::vector<bool> callVisited=std::vector<bool>(cmIdLen,false);
|
||||
auto cmIter=confirmedMatches.begin();
|
||||
for (int i=0; i<(int)renderedCmds.size(); i++) {
|
||||
int writeCall=-1;
|
||||
TiunaBytes cmd=renderedCmds[i];
|
||||
if (cmIter!=confirmedMatches.end() && i==cmIter->pos) {
|
||||
if (cmIter->id<cmIdLen) {
|
||||
if (callVisited[cmIter->id]) {
|
||||
unsigned char idLo=cmIter->id&0xff;
|
||||
unsigned char idHi=cmIter->id>>8;
|
||||
cmd={cmd.ch,0,2,{idHi,idLo}};
|
||||
i=cmIter->endPos-1;
|
||||
} else {
|
||||
writeCall=cmIter->id;
|
||||
callVisited[writeCall]=true;
|
||||
}
|
||||
}
|
||||
cmIter++;
|
||||
}
|
||||
if (cmd.ch!=curCh) {
|
||||
if (curCh>=0) {
|
||||
w->writeText(" .text x\"e0\"\n");
|
||||
totalSize++;
|
||||
bankSize++;
|
||||
}
|
||||
if (bankSize+cmd.size>=maxBankSize) {
|
||||
maxBankSize=otherBankSize;
|
||||
curBank++;
|
||||
w->writeText(fmt::format(" .endsection\n\n .section {}_bank{}",baseLabel,curBank));
|
||||
bankSize=0;
|
||||
}
|
||||
w->writeText(fmt::format("\n{}_ch{}\n",baseLabel,cmd.ch));
|
||||
curCh=cmd.ch;
|
||||
}
|
||||
if (bankSize+cmd.size+1>=maxBankSize) {
|
||||
maxBankSize=otherBankSize;
|
||||
curBank++;
|
||||
w->writeText(fmt::format(" .text x\"c0\"\n .endsection\n\n .section {}_bank{}\n",baseLabel,curBank));
|
||||
totalSize++;
|
||||
bankSize=0;
|
||||
}
|
||||
if (writeCall>=0) {
|
||||
w->writeText(fmt::format("{}_c{}\n",baseLabel,writeCall));
|
||||
}
|
||||
w->writeText(" .text x\"");
|
||||
for (int j=0; j<cmd.size; j++) {
|
||||
w->writeText(fmt::format("{:02x}",cmd.buf[j]));
|
||||
}
|
||||
w->writeText("\"\n");
|
||||
totalSize+=cmd.size;
|
||||
bankSize+=cmd.size;
|
||||
}
|
||||
w->writeText(" .text x\"e0\"\n .endsection\n");
|
||||
totalSize++;
|
||||
logI("total size: %d bytes (%d banks)",totalSize,curBank+1);
|
||||
|
||||
FILE* f=ps_fopen("confirmedMatches.txt","wb");
|
||||
if (f!=NULL) {
|
||||
fwrite(dbg.getFinalBuf(),1,dbg.size(),f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
|
@ -931,6 +931,7 @@ void FurnaceGUI::doAction(int what) {
|
|||
sample->loop=prevSample->loop;
|
||||
sample->loopMode=prevSample->loopMode;
|
||||
sample->brrEmphasis=prevSample->brrEmphasis;
|
||||
sample->brrNoFilter=prevSample->brrNoFilter;
|
||||
sample->dither=prevSample->dither;
|
||||
sample->depth=prevSample->depth;
|
||||
if (sample->init(prevSample->samples)) {
|
||||
|
|
|
@ -249,6 +249,56 @@ void FurnaceGUI::drawExportZSM(bool onWindow) {
|
|||
}
|
||||
}
|
||||
|
||||
void FurnaceGUI::drawExportTiuna(bool onWindow) {
|
||||
exitDisabledTimer=1;
|
||||
|
||||
ImGui::Text("this is NOT ROM export! (for now)\nfor use with TIunA driver, outputs asm source.");
|
||||
ImGui::InputText("base song label name", &asmBaseLabel); //TODO validate label
|
||||
if (ImGui::InputInt("max size in first bank",&tiunaFirstBankSize,1,100)) {
|
||||
if (tiunaFirstBankSize<0) tiunaFirstBankSize=0;
|
||||
if (tiunaFirstBankSize>4096) tiunaFirstBankSize=4096;
|
||||
}
|
||||
if (ImGui::InputInt("max size in other banks",&tiunaOtherBankSize,1,100)) {
|
||||
if (tiunaOtherBankSize<16) tiunaOtherBankSize=16;
|
||||
if (tiunaOtherBankSize>4096) tiunaOtherBankSize=4096;
|
||||
}
|
||||
|
||||
ImGui::Text("chips to export:");
|
||||
int selected=0;
|
||||
for (int i=0; i<e->song.systemLen; i++) {
|
||||
DivSystem sys=e->song.system[i];
|
||||
bool isTIA=sys==DIV_SYSTEM_TIA;
|
||||
ImGui::BeginDisabled((!isTIA) || (selected>=1));
|
||||
ImGui::Checkbox(fmt::sprintf("%d. %s##_SYSV%d",i+1,getSystemName(e->song.system[i]),i).c_str(),&willExport[i]);
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
|
||||
if (!isTIA) {
|
||||
ImGui::SetTooltip("this chip is not supported by the file format!");
|
||||
} else if (selected>=1) {
|
||||
ImGui::SetTooltip("only one Atari TIA is supported!");
|
||||
}
|
||||
}
|
||||
if (isTIA && willExport[i]) selected++;
|
||||
}
|
||||
if (selected>0) {
|
||||
if (onWindow) {
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Cancel",ImVec2(200.0f*dpiScale,0))) ImGui::CloseCurrentPopup();
|
||||
ImGui::SameLine();
|
||||
}
|
||||
if (ImGui::Button("Export",ImVec2(200.0f*dpiScale,0))) {
|
||||
openFileDialog(GUI_FILE_EXPORT_TIUNA);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
} else {
|
||||
ImGui::Text("nothing to export");
|
||||
if (onWindow) {
|
||||
ImGui::Separator();
|
||||
if (ImGui::Button("Cancel",ImVec2(400.0f*dpiScale,0))) ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FurnaceGUI::drawExportAmigaVal(bool onWindow) {
|
||||
exitDisabledTimer=1;
|
||||
|
||||
|
@ -372,6 +422,19 @@ void FurnaceGUI::drawExport() {
|
|||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
bool hasTiunaCompat=false;
|
||||
for (int i=0; i<e->song.systemLen; i++) {
|
||||
if (e->song.system[i]==DIV_SYSTEM_TIA) {
|
||||
hasTiunaCompat=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasTiunaCompat) {
|
||||
if (ImGui::BeginTabItem("TIunA")) {
|
||||
drawExportTiuna(true);
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
}
|
||||
int numAmiga=0;
|
||||
for (int i=0; i<e->song.systemLen; i++) {
|
||||
if (e->song.system[i]==DIV_SYSTEM_AMIGA) numAmiga++;
|
||||
|
@ -406,6 +469,9 @@ void FurnaceGUI::drawExport() {
|
|||
case GUI_EXPORT_ZSM:
|
||||
drawExportZSM(true);
|
||||
break;
|
||||
case GUI_EXPORT_TIUNA:
|
||||
drawExportTiuna(true);
|
||||
break;
|
||||
case GUI_EXPORT_AMIGA_VAL:
|
||||
drawExportAmigaVal(true);
|
||||
break;
|
||||
|
|
|
@ -1926,6 +1926,15 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
|||
(settings.autoFillSave)?shortName:""
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_TIUNA:
|
||||
if (!dirExists(workingDirTiunaExport)) workingDirTiunaExport=getHomeDir();
|
||||
hasOpened=fileDialog->openSave(
|
||||
"Export TIunA",
|
||||
{"assembly files", "*.asm"},
|
||||
workingDirTiunaExport,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_TEXT:
|
||||
if (!dirExists(workingDirROMExport)) workingDirROMExport=getHomeDir();
|
||||
hasOpened=fileDialog->openSave(
|
||||
|
@ -4894,6 +4903,9 @@ bool FurnaceGUI::loop() {
|
|||
case GUI_FILE_EXPORT_ZSM:
|
||||
workingDirZSMExport=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_EXPORT_TIUNA:
|
||||
workingDirTiunaExport=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_EXPORT_ROM:
|
||||
case GUI_FILE_EXPORT_TEXT:
|
||||
case GUI_FILE_EXPORT_CMDSTREAM:
|
||||
|
@ -5375,6 +5387,27 @@ bool FurnaceGUI::loop() {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case GUI_FILE_EXPORT_TIUNA: {
|
||||
SafeWriter* w=e->saveTiuna(willExport,asmBaseLabel.c_str(),tiunaFirstBankSize,tiunaOtherBankSize);
|
||||
if (w!=NULL) {
|
||||
FILE* f=ps_fopen(copyOfName.c_str(),"wb");
|
||||
if (f!=NULL) {
|
||||
fwrite(w->getFinalBuf(),1,w->size(),f);
|
||||
fclose(f);
|
||||
pushRecentSys(copyOfName.c_str());
|
||||
} else {
|
||||
showError("could not open file!");
|
||||
}
|
||||
w->finish();
|
||||
delete w;
|
||||
if (!e->getWarnings().empty()) {
|
||||
showWarning(e->getWarnings(),GUI_WARN_GENERIC);
|
||||
}
|
||||
} else {
|
||||
showError(fmt::sprintf("Could not write TIunA! (%s)",e->getLastError()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GUI_FILE_EXPORT_ROM:
|
||||
showError(_("Coming soon!"));
|
||||
break;
|
||||
|
@ -7271,6 +7304,7 @@ void FurnaceGUI::syncState() {
|
|||
workingDirAudioExport=e->getConfString("lastDirAudioExport",workingDir);
|
||||
workingDirVGMExport=e->getConfString("lastDirVGMExport",workingDir);
|
||||
workingDirZSMExport=e->getConfString("lastDirZSMExport",workingDir);
|
||||
workingDirTiunaExport=e->getConfString("lastDirTiunaExport",workingDir);
|
||||
workingDirROMExport=e->getConfString("lastDirROMExport",workingDir);
|
||||
workingDirFont=e->getConfString("lastDirFont",workingDir);
|
||||
workingDirColors=e->getConfString("lastDirColors",workingDir);
|
||||
|
@ -7430,6 +7464,7 @@ void FurnaceGUI::commitState(DivConfig& conf) {
|
|||
conf.set("lastDirAudioExport",workingDirAudioExport);
|
||||
conf.set("lastDirVGMExport",workingDirVGMExport);
|
||||
conf.set("lastDirZSMExport",workingDirZSMExport);
|
||||
conf.set("lastDirTiunaExport",workingDirTiunaExport);
|
||||
conf.set("lastDirROMExport",workingDirROMExport);
|
||||
conf.set("lastDirFont",workingDirFont);
|
||||
conf.set("lastDirColors",workingDirColors);
|
||||
|
@ -7689,6 +7724,9 @@ FurnaceGUI::FurnaceGUI():
|
|||
vgmExportTrailingTicks(-1),
|
||||
drawHalt(10),
|
||||
zsmExportTickRate(60),
|
||||
asmBaseLabel(""),
|
||||
tiunaFirstBankSize(3072),
|
||||
tiunaOtherBankSize(4096-48),
|
||||
macroPointSize(16),
|
||||
waveEditStyle(0),
|
||||
displayInsTypeListMakeInsSample(-1),
|
||||
|
|
|
@ -591,6 +591,7 @@ enum FurnaceGUIFileDialogs {
|
|||
GUI_FILE_EXPORT_AUDIO_PER_CHANNEL,
|
||||
GUI_FILE_EXPORT_VGM,
|
||||
GUI_FILE_EXPORT_ZSM,
|
||||
GUI_FILE_EXPORT_TIUNA,
|
||||
GUI_FILE_EXPORT_CMDSTREAM,
|
||||
GUI_FILE_EXPORT_TEXT,
|
||||
GUI_FILE_EXPORT_ROM,
|
||||
|
@ -643,6 +644,7 @@ enum FurnaceGUIExportTypes {
|
|||
GUI_EXPORT_AUDIO=0,
|
||||
GUI_EXPORT_VGM,
|
||||
GUI_EXPORT_ZSM,
|
||||
GUI_EXPORT_TIUNA,
|
||||
GUI_EXPORT_CMD_STREAM,
|
||||
GUI_EXPORT_AMIGA_VAL,
|
||||
GUI_EXPORT_TEXT,
|
||||
|
@ -1581,7 +1583,8 @@ class FurnaceGUI {
|
|||
|
||||
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile, sysSearchQuery, newSongQuery, paletteQuery;
|
||||
String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport;
|
||||
String workingDirVGMExport, workingDirZSMExport, workingDirROMExport, workingDirFont, workingDirColors, workingDirKeybinds;
|
||||
String workingDirVGMExport, workingDirZSMExport, workingDirTiunaExport, workingDirROMExport;
|
||||
String workingDirFont, workingDirColors, workingDirKeybinds;
|
||||
String workingDirLayout, workingDirROM, workingDirTest;
|
||||
String workingDirConfig;
|
||||
String mmlString[32];
|
||||
|
@ -1618,6 +1621,9 @@ class FurnaceGUI {
|
|||
int cvHiScore;
|
||||
int drawHalt;
|
||||
int zsmExportTickRate;
|
||||
String asmBaseLabel;
|
||||
int tiunaFirstBankSize;
|
||||
int tiunaOtherBankSize;
|
||||
int macroPointSize;
|
||||
int waveEditStyle;
|
||||
int displayInsTypeListMakeInsSample;
|
||||
|
@ -2669,6 +2675,7 @@ class FurnaceGUI {
|
|||
void drawExportAudio(bool onWindow=false);
|
||||
void drawExportVGM(bool onWindow=false);
|
||||
void drawExportZSM(bool onWindow=false);
|
||||
void drawExportTiuna(bool onWindow=false);
|
||||
void drawExportAmigaVal(bool onWindow=false);
|
||||
void drawExportText(bool onWindow=false);
|
||||
void drawExportCommand(bool onWindow=false);
|
||||
|
|
|
@ -254,12 +254,23 @@ void FurnaceGUI::initSystemPresets() {
|
|||
CH(DIV_SYSTEM_TIA, 1.0f, 0, "")
|
||||
}
|
||||
);
|
||||
SUB_ENTRY(
|
||||
"Atari 2600/7800 (with software pitch driver)", {
|
||||
CH(DIV_SYSTEM_TIA, 1.0f, 0, "softwarePitch=1")
|
||||
}
|
||||
);
|
||||
ENTRY(
|
||||
"Atari 7800 + Ballblazer/Commando", {
|
||||
CH(DIV_SYSTEM_TIA, 1.0f, 0, ""),
|
||||
CH(DIV_SYSTEM_POKEY, 1.0f, 0, "")
|
||||
}
|
||||
);
|
||||
SUB_ENTRY(
|
||||
"Atari 7800 (with software pitch driver) + Ballblazer/Commando", {
|
||||
CH(DIV_SYSTEM_TIA, 1.0f, 0, "softwarePitch=1"),
|
||||
CH(DIV_SYSTEM_POKEY, 1.0f, 0, "")
|
||||
}
|
||||
);
|
||||
ENTRY(
|
||||
"Atari Lynx", {
|
||||
CH(DIV_SYSTEM_LYNX, 1.0f, 0, "")
|
||||
|
@ -2978,6 +2989,11 @@ void FurnaceGUI::initSystemPresets() {
|
|||
CH(DIV_SYSTEM_TIA, 1.0f, 0, "")
|
||||
}
|
||||
);
|
||||
SUB_ENTRY(
|
||||
"Atari TIA (with software pitch driver)", {
|
||||
CH(DIV_SYSTEM_TIA, 1.0f, 0, "softwarePitch=1")
|
||||
}
|
||||
);
|
||||
ENTRY(
|
||||
"NES (Ricoh 2A03)", {
|
||||
CH(DIV_SYSTEM_NES, 1.0f, 0, "")
|
||||
|
|
|
@ -541,6 +541,19 @@ void FurnaceGUI::drawSampleEdit() {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (sample->depth!=DIV_SAMPLE_DEPTH_BRR && isThereSNES) {
|
||||
bool bf=sample->brrNoFilter;
|
||||
if (ImGui::Checkbox(_("no BRR filters"),&bf)) {
|
||||
sample->prepareUndo(true);
|
||||
sample->brrNoFilter=bf;
|
||||
e->renderSamplesP(curSample);
|
||||
updateSampleTex=true;
|
||||
MARK_MODIFIED;
|
||||
}
|
||||
if (ImGui::IsItemHovered()) {
|
||||
ImGui::SetTooltip(_("enable this option to not use BRR blocks with filters\nand allow sample offset commands to be used safely."));
|
||||
}
|
||||
}
|
||||
if (sample->depth!=DIV_SAMPLE_DEPTH_8BIT && e->getSampleFormatMask()&(1L<<DIV_SAMPLE_DEPTH_8BIT)) {
|
||||
bool di=sample->dither;
|
||||
if (ImGui::Checkbox(_("8-bit dither"),&di)) {
|
||||
|
|
|
@ -1061,6 +1061,18 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl
|
|||
case DIV_SYSTEM_TIA: {
|
||||
bool clockSel=flags.getInt("clockSel",0);
|
||||
int mixingType=flags.getInt("mixingType",0);
|
||||
bool softwarePitch=flags.getBool("softwarePitch",false);
|
||||
bool oldPitch=flags.getBool("oldPitch",false);
|
||||
|
||||
ImGui::BeginDisabled(oldPitch);
|
||||
if (ImGui::Checkbox(_("Software pitch driver"),&softwarePitch)) {
|
||||
altered=true;
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
if (ImGui::Checkbox(_("Old pitch table (compatibility)"),&oldPitch)) {
|
||||
if (oldPitch) softwarePitch=false;
|
||||
altered=true;
|
||||
}
|
||||
|
||||
ImGui::Text(_("Mixing mode:"));
|
||||
ImGui::Indent();
|
||||
|
@ -1086,6 +1098,8 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl
|
|||
e->lockSave([&]() {
|
||||
flags.set("clockSel",(int)clockSel);
|
||||
flags.set("mixingType",mixingType);
|
||||
flags.set("softwarePitch",softwarePitch);
|
||||
flags.set("oldPitch",oldPitch);
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
@ -2436,12 +2450,33 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl
|
|||
}
|
||||
break;
|
||||
}
|
||||
case DIV_SYSTEM_VERA: {
|
||||
int chipType=flags.getInt("chipType",1);
|
||||
|
||||
ImGui::Text(_("Chip revision:"));
|
||||
ImGui::Indent();
|
||||
if (ImGui::RadioButton(_("V 0.3.1"),chipType==0)) {
|
||||
chipType=0;
|
||||
altered=true;
|
||||
}
|
||||
if (ImGui::RadioButton(_("V 47.0.0 (9-bit volume)"),chipType==1)) {
|
||||
chipType=1;
|
||||
altered=true;
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
if (altered) {
|
||||
e->lockSave([&]() {
|
||||
flags.set("chipType",chipType);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DIV_SYSTEM_SWAN:
|
||||
case DIV_SYSTEM_BUBSYS_WSG:
|
||||
case DIV_SYSTEM_PET:
|
||||
case DIV_SYSTEM_GA20:
|
||||
case DIV_SYSTEM_PV1000:
|
||||
case DIV_SYSTEM_VERA:
|
||||
case DIV_SYSTEM_C219:
|
||||
case DIV_SYSTEM_BIFURCATOR:
|
||||
case DIV_SYSTEM_POWERNOISE:
|
||||
|
|
Loading…
Reference in a new issue