Merge branch 'master' into sample_banks
This commit is contained in:
commit
e3e61c817c
183 changed files with 1384 additions and 777 deletions
|
|
@ -3589,6 +3589,12 @@ void DivEngine::synchronized(const std::function<void()>& what) {
|
|||
BUSY_END;
|
||||
}
|
||||
|
||||
void DivEngine::synchronizedSoft(const std::function<void()>& what) {
|
||||
BUSY_BEGIN_SOFT;
|
||||
what();
|
||||
BUSY_END;
|
||||
}
|
||||
|
||||
void DivEngine::lockSave(const std::function<void()>& what) {
|
||||
saveLock.lock();
|
||||
what();
|
||||
|
|
@ -3916,6 +3922,9 @@ bool DivEngine::preInit(bool noSafeMode) {
|
|||
// register systems
|
||||
if (!systemsRegistered) registerSystems();
|
||||
|
||||
// register ROM exports
|
||||
if (!romExportsRegistered) registerROMExports();
|
||||
|
||||
// TODO: re-enable with a better approach
|
||||
// see issue #1581
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -54,8 +54,8 @@ class DivWorkPool;
|
|||
|
||||
#define DIV_UNSTABLE
|
||||
|
||||
#define DIV_VERSION "Import Test"
|
||||
#define DIV_ENGINE_VERSION 216
|
||||
#define DIV_VERSION "dev217"
|
||||
#define DIV_ENGINE_VERSION 217
|
||||
// for imports
|
||||
#define DIV_VERSION_MOD 0xff01
|
||||
#define DIV_VERSION_FC 0xff02
|
||||
|
|
@ -465,6 +465,7 @@ class DivEngine {
|
|||
bool midiIsDirectProgram;
|
||||
bool lowLatency;
|
||||
bool systemsRegistered;
|
||||
bool romExportsRegistered;
|
||||
bool hasLoadedSomething;
|
||||
bool midiOutClock;
|
||||
bool midiOutTime;
|
||||
|
|
@ -518,6 +519,7 @@ class DivEngine {
|
|||
static DivSysDef* sysDefs[DIV_MAX_CHIP_DEFS];
|
||||
static DivSystem sysFileMapFur[DIV_MAX_CHIP_DEFS];
|
||||
static DivSystem sysFileMapDMF[DIV_MAX_CHIP_DEFS];
|
||||
static DivROMExportDef* romExportDefs[DIV_ROM_MAX];
|
||||
|
||||
DivCSPlayer* cmdStreamInt;
|
||||
|
||||
|
|
@ -635,6 +637,7 @@ class DivEngine {
|
|||
bool deinitAudioBackend(bool dueToSwitchMaster=false);
|
||||
|
||||
void registerSystems();
|
||||
void registerROMExports();
|
||||
void initSongWithDesc(const char* description, bool inBase64=true, bool oldVol=false);
|
||||
|
||||
void exchangeIns(int one, int two);
|
||||
|
|
@ -665,6 +668,7 @@ class DivEngine {
|
|||
// add every export method here
|
||||
friend class DivROMExport;
|
||||
friend class DivExportAmigaValidation;
|
||||
friend class DivExportTiuna;
|
||||
|
||||
public:
|
||||
DivSong song;
|
||||
|
|
@ -895,6 +899,9 @@ class DivEngine {
|
|||
// get sys definition
|
||||
const DivSysDef* getSystemDef(DivSystem sys);
|
||||
|
||||
// get ROM export definition
|
||||
const DivROMExportDef* getROMExportDef(DivROMExportOptions opt);
|
||||
|
||||
// convert sample rate format
|
||||
int fileToDivRate(int frate);
|
||||
int divToFileRate(int drate);
|
||||
|
|
@ -1305,6 +1312,9 @@ class DivEngine {
|
|||
// perform secure/sync operation
|
||||
void synchronized(const std::function<void()>& what);
|
||||
|
||||
// perform secure/sync operation (soft)
|
||||
void synchronizedSoft(const std::function<void()>& what);
|
||||
|
||||
// perform secure/sync song operation
|
||||
void lockSave(const std::function<void()>& what);
|
||||
|
||||
|
|
@ -1372,6 +1382,7 @@ class DivEngine {
|
|||
midiIsDirectProgram(false),
|
||||
lowLatency(false),
|
||||
systemsRegistered(false),
|
||||
romExportsRegistered(false),
|
||||
hasLoadedSomething(false),
|
||||
midiOutClock(false),
|
||||
midiOutTime(false),
|
||||
|
|
@ -1478,6 +1489,7 @@ class DivEngine {
|
|||
memset(pitchTable,0,4096*sizeof(int));
|
||||
memset(effectSlotMap,-1,4096*sizeof(short));
|
||||
memset(sysDefs,0,DIV_MAX_CHIP_DEFS*sizeof(void*));
|
||||
memset(romExportDefs,0,DIV_ROM_MAX*sizeof(void*));
|
||||
memset(walked,0,8192);
|
||||
memset(oscBuf,0,DIV_MAX_OUTPUTS*(sizeof(float*)));
|
||||
memset(exportChannelMask,1,DIV_MAX_CHANS*sizeof(bool));
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "engine.h"
|
||||
|
||||
#include "export/amigaValidation.h"
|
||||
#include "export/tiuna.h"
|
||||
|
||||
DivROMExport* DivEngine::buildROM(DivROMExportOptions sys) {
|
||||
DivROMExport* exporter=NULL;
|
||||
|
|
@ -27,6 +28,9 @@ DivROMExport* DivEngine::buildROM(DivROMExportOptions sys) {
|
|||
case DIV_ROM_AMIGA_VALIDATION:
|
||||
exporter=new DivExportAmigaValidation;
|
||||
break;
|
||||
case DIV_ROM_TIUNA:
|
||||
exporter=new DivExportTiuna;
|
||||
break;
|
||||
default:
|
||||
exporter=new DivROMExport;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class DivEngine;
|
|||
enum DivROMExportOptions {
|
||||
DIV_ROM_ABSTRACT=0,
|
||||
DIV_ROM_AMIGA_VALIDATION,
|
||||
DIV_ROM_ZSM,
|
||||
DIV_ROM_TIUNA,
|
||||
|
||||
DIV_ROM_MAX
|
||||
};
|
||||
|
|
@ -52,39 +54,54 @@ struct DivROMExportProgress {
|
|||
|
||||
class DivROMExport {
|
||||
protected:
|
||||
std::vector<String> exportLog;
|
||||
DivConfig conf;
|
||||
std::vector<DivROMExportOutput> output;
|
||||
std::mutex logLock;
|
||||
void logAppend(String what);
|
||||
public:
|
||||
std::vector<String> exportLog;
|
||||
std::mutex logLock;
|
||||
|
||||
void setConf(DivConfig& c);
|
||||
virtual bool go(DivEngine* eng);
|
||||
virtual void abort();
|
||||
virtual void wait();
|
||||
std::vector<DivROMExportOutput>& getResult();
|
||||
virtual bool hasFailed();
|
||||
virtual bool isRunning();
|
||||
virtual DivROMExportProgress getProgress();
|
||||
virtual DivROMExportProgress getProgress(int index=0);
|
||||
virtual ~DivROMExport() {}
|
||||
};
|
||||
|
||||
#define logAppendf(...) logAppend(fmt::sprintf(__VA_ARGS__))
|
||||
|
||||
enum DivROMExportReqPolicy {
|
||||
// exactly these chips.
|
||||
DIV_REQPOL_EXACT=0,
|
||||
// specified chips must be present but any amount of them is acceptable.
|
||||
DIV_REQPOL_ANY,
|
||||
// at least one of the specified chips.
|
||||
DIV_REQPOL_LAX
|
||||
};
|
||||
|
||||
struct DivROMExportDef {
|
||||
const char* name;
|
||||
const char* author;
|
||||
const char* description;
|
||||
DivSystem requisites[32];
|
||||
int requisitesLen;
|
||||
const char* fileType;
|
||||
const char* fileExt;
|
||||
std::vector<DivSystem> requisites;
|
||||
bool multiOutput;
|
||||
DivROMExportReqPolicy requisitePolicy;
|
||||
|
||||
DivROMExportDef(const char* n, const char* a, const char* d, std::initializer_list<DivSystem> req, bool multiOut):
|
||||
DivROMExportDef(const char* n, const char* a, const char* d, const char* ft, const char* fe, std::initializer_list<DivSystem> req, bool multiOut, DivROMExportReqPolicy reqPolicy):
|
||||
name(n),
|
||||
author(a),
|
||||
description(d),
|
||||
multiOutput(multiOut) {
|
||||
requisitesLen=0;
|
||||
memset(requisites,0,32*sizeof(DivSystem));
|
||||
for (DivSystem i: req) {
|
||||
requisites[requisitesLen++]=i;
|
||||
}
|
||||
fileType(ft),
|
||||
fileExt(fe),
|
||||
multiOutput(multiOut),
|
||||
requisitePolicy(reqPolicy) {
|
||||
requisites=req;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ bool DivROMExport::hasFailed() {
|
|||
return true;
|
||||
}
|
||||
|
||||
DivROMExportProgress DivROMExport::getProgress() {
|
||||
DivROMExportProgress DivROMExport::getProgress(int index) {
|
||||
DivROMExportProgress ret;
|
||||
ret.name="Test";
|
||||
ret.name="";
|
||||
ret.amount=0.0f;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -55,3 +55,7 @@ void DivROMExport::wait() {
|
|||
bool DivROMExport::isRunning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void DivROMExport::setConf(DivConfig& c) {
|
||||
conf=c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ void DivExportAmigaValidation::run() {
|
|||
bool done=false;
|
||||
|
||||
// sample.bin
|
||||
logAppend("writing samples...");
|
||||
SafeWriter* sample=new SafeWriter;
|
||||
sample->init();
|
||||
for (int i=0; i<256; i++) {
|
||||
|
|
@ -79,6 +80,7 @@ void DivExportAmigaValidation::run() {
|
|||
if (sample->tell()&1) sample->writeC(0);
|
||||
|
||||
// seq.bin
|
||||
logAppend("making sequence...");
|
||||
SafeWriter* seq=new SafeWriter;
|
||||
seq->init();
|
||||
|
||||
|
|
@ -239,6 +241,7 @@ void DivExportAmigaValidation::run() {
|
|||
EXTERN_BUSY_END;
|
||||
|
||||
// wave.bin
|
||||
logAppend("writing wavetables...");
|
||||
SafeWriter* wave=new SafeWriter;
|
||||
wave->init();
|
||||
for (WaveEntry& i: waves) {
|
||||
|
|
@ -246,6 +249,7 @@ void DivExportAmigaValidation::run() {
|
|||
}
|
||||
|
||||
// sbook.bin
|
||||
logAppend("writing sample book...");
|
||||
SafeWriter* sbook=new SafeWriter;
|
||||
sbook->init();
|
||||
for (SampleBookEntry& i: sampleBook) {
|
||||
|
|
@ -255,6 +259,7 @@ void DivExportAmigaValidation::run() {
|
|||
}
|
||||
|
||||
// wbook.bin
|
||||
logAppend("writing wavetable book...");
|
||||
SafeWriter* wbook=new SafeWriter;
|
||||
wbook->init();
|
||||
for (WaveEntry& i: waves) {
|
||||
|
|
@ -272,6 +277,8 @@ void DivExportAmigaValidation::run() {
|
|||
output.push_back(DivROMExportOutput("wave.bin",wave));
|
||||
output.push_back(DivROMExportOutput("seq.bin",seq));
|
||||
|
||||
logAppend("finished!");
|
||||
|
||||
running=false;
|
||||
}
|
||||
|
||||
|
|
@ -296,3 +303,7 @@ void DivExportAmigaValidation::abort() {
|
|||
bool DivExportAmigaValidation::isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
bool DivExportAmigaValidation::hasFailed() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ class DivExportAmigaValidation: public DivROMExport {
|
|||
public:
|
||||
bool go(DivEngine* e);
|
||||
bool isRunning();
|
||||
bool hasFailed();
|
||||
void abort();
|
||||
void wait();
|
||||
~DivExportAmigaValidation() {}
|
||||
|
|
|
|||
|
|
@ -17,13 +17,14 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "tiuna.h"
|
||||
#include "../engine.h"
|
||||
#include "../ta-log.h"
|
||||
#include <fmt/printf.h>
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include "engine.h"
|
||||
#include "../fileutils.h"
|
||||
#include "../ta-log.h"
|
||||
|
||||
struct TiunaNew {
|
||||
short pitch;
|
||||
|
|
@ -180,140 +181,161 @@ static void writeCmd(std::vector<TiunaBytes>& cmds, TiunaCmd& cmd, unsigned char
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
void DivExportTiuna::run() {
|
||||
int loopOrder, loopOrderRow, loopEnd;
|
||||
int tick=0;
|
||||
// int loopTick=-1;
|
||||
TiunaLast last[2];
|
||||
TiunaNew news[2];
|
||||
SafeWriter* w;
|
||||
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;
|
||||
// config
|
||||
String baseLabel=conf.getString("baseLabel","song");
|
||||
int firstBankSize=conf.getInt("firstBankSize",3072);
|
||||
int otherBankSize=conf.getInt("otherBankSize",4096-48);
|
||||
int tiaIdx=conf.getInt("sysToExport",-1);
|
||||
|
||||
e->stop();
|
||||
e->repeatPattern=false;
|
||||
e->shallStop=false;
|
||||
e->setOrder(0);
|
||||
e->synchronizedSoft([&]() {
|
||||
// determine loop point
|
||||
// bool stopped=false;
|
||||
loopOrder=0;
|
||||
loopOrderRow=0;
|
||||
loopEnd=0;
|
||||
e->walkSong(loopOrder,loopOrderRow,loopEnd);
|
||||
logAppendf("loop point: %d %d",loopOrder,loopOrderRow);
|
||||
|
||||
w=new SafeWriter;
|
||||
w->init();
|
||||
|
||||
if (tiaIdx<0 || tiaIdx>=e->song.systemLen) {
|
||||
tiaIdx=-1;
|
||||
for (int i=0; i<e->song.systemLen; i++) {
|
||||
if (e->song.system[i]==DIV_SYSTEM_TIA) {
|
||||
tiaIdx=i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (tiaIdx<0) {
|
||||
logAppend("ERROR: selected TIA system not found");
|
||||
failed=true;
|
||||
running=false;
|
||||
return;
|
||||
}
|
||||
} else if (e->song.system[tiaIdx]!=DIV_SYSTEM_TIA) {
|
||||
logAppend("ERROR: selected chip is not a TIA!");
|
||||
failed=true;
|
||||
running=false;
|
||||
return;
|
||||
}
|
||||
|
||||
e->disCont[tiaIdx].dispatch->toggleRegisterDump(true);
|
||||
|
||||
// write patterns
|
||||
// bool writeLoop=false;
|
||||
logAppend("recording sequence...");
|
||||
bool done=false;
|
||||
e->playSub(false);
|
||||
|
||||
// int loopTick=-1;
|
||||
TiunaLast last[2];
|
||||
TiunaNew news[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 (e->nextTick(false,true) || !e->playing) {
|
||||
// stopped=!playing;
|
||||
done=true;
|
||||
break;
|
||||
}
|
||||
for (int i=0; i<2; i++) {
|
||||
news[i]=TiunaNew();
|
||||
}
|
||||
// get register dumps
|
||||
std::vector<DivRegWrite>& writes=e->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;
|
||||
}
|
||||
e->cmdStream.clear();
|
||||
tick++;
|
||||
}
|
||||
for (int i=0; i<e->song.systemLen; i++) {
|
||||
e->disCont[i].dispatch->getRegisterWrites().clear();
|
||||
e->disCont[i].dispatch->toggleRegisterDump(false);
|
||||
}
|
||||
|
||||
e->remainingLoops=-1;
|
||||
e->playing=false;
|
||||
e->freelance=false;
|
||||
e->extValuePresent=false;
|
||||
});
|
||||
|
||||
if (failed) return;
|
||||
|
||||
// render commands
|
||||
logAppend("rendering commands...");
|
||||
std::vector<TiunaBytes> renderedCmds;
|
||||
w->writeText(fmt::format(
|
||||
"; Generated by Furnace " DIV_VERSION "\n"
|
||||
|
|
@ -321,7 +343,7 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
"; Author: {}\n"
|
||||
"; Album: {}\n"
|
||||
"; Subsong #{}: {}\n\n",
|
||||
song.name,song.author,song.category,curSubSongIndex+1,curSubSong->name
|
||||
e->song.name,e->song.author,e->song.category,e->curSubSongIndex+1,e->curSubSong->name
|
||||
));
|
||||
for (int i=0; i<2; i++) {
|
||||
TiunaCmd lastCmd;
|
||||
|
|
@ -349,15 +371,30 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
int cmdSize=renderedCmds.size();
|
||||
bool* processed=new bool[cmdSize];
|
||||
memset(processed,0,cmdSize*sizeof(bool));
|
||||
logI("max cmId: %d",(MAX(firstBankSize/1024,1))*256);
|
||||
while (firstBankSize>768 && cmId<(MAX(firstBankSize/1024,1))*256) {
|
||||
logI("start CM %04x...",cmId);
|
||||
logAppend("compressing! this may take a while.");
|
||||
int maxCmId=(MAX(firstBankSize/1024,1))*256;
|
||||
int lastMaxPMVal=100000;
|
||||
logAppendf("max cmId: %d",maxCmId);
|
||||
logAppendf("commands: %d",cmdSize);
|
||||
while (firstBankSize>768 && cmId<maxCmId) {
|
||||
if (mustAbort) {
|
||||
logAppend("aborted!");
|
||||
failed=true;
|
||||
running=false;
|
||||
delete[] processed;
|
||||
return;
|
||||
}
|
||||
|
||||
float theOtherSide=pow(1.0/float(MAX(1,lastMaxPMVal)),0.2)*0.98;
|
||||
progress[0].amount=theOtherSide+(1.0-theOtherSide)*((float)cmId/(float)maxCmId);
|
||||
|
||||
logAppendf("start CM %04x...",cmId);
|
||||
std::map<int,TiunaMatches> potentialMatches;
|
||||
logD("scan %d size...",cmdSize-1);
|
||||
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;
|
||||
progress[1].amount=(float)i/(float)(cmdSize-1);
|
||||
std::vector<TiunaMatch> match;
|
||||
int ch=renderedCmds[i].ch;
|
||||
for (int j=i+1; j<cmdSize;) {
|
||||
|
|
@ -427,12 +464,11 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
i++;
|
||||
}
|
||||
if (potentialMatches.empty()) {
|
||||
logV("potentialMatches is empty");
|
||||
logAppend("potentialMatches is empty");
|
||||
break;
|
||||
}
|
||||
int maxPMIdx=0;
|
||||
int maxPMVal=0;
|
||||
logV("looking through potentialMatches...");
|
||||
for (const auto& i: potentialMatches) {
|
||||
if (i.second.bytesSaved>maxPMVal) {
|
||||
maxPMVal=i.second.bytesSaved;
|
||||
|
|
@ -440,16 +476,19 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
}
|
||||
}
|
||||
int maxPMLen=potentialMatches[maxPMIdx].length;
|
||||
logV("the other step...");
|
||||
for (const int i: potentialMatches[maxPMIdx].pos) {
|
||||
confirmedMatches.push_back({i,i+maxPMLen,0,cmId});
|
||||
memset(processed+i,1,maxPMLen);
|
||||
//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);
|
||||
logAppendf("CM %04x added: pos=%d,len=%d,matches=%d,saved=%d",cmId,maxPMIdx,maxPMLen,potentialMatches[maxPMIdx].pos.size(),maxPMVal);
|
||||
lastMaxPMVal=maxPMVal;
|
||||
cmId++;
|
||||
}
|
||||
progress[0].amount=1.0f;
|
||||
progress[1].amount=1.0f;
|
||||
logAppend("generating data...");
|
||||
delete[] processed;
|
||||
std::sort(confirmedMatches.begin(),confirmedMatches.end(),[](const TiunaMatch& l, const TiunaMatch& r){
|
||||
return l.pos<r.pos;
|
||||
|
|
@ -460,8 +499,10 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
// 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;
|
||||
logAppend("ERROR: impossible overlap found in matches list, please report");
|
||||
failed=true;
|
||||
running=false;
|
||||
return;
|
||||
}
|
||||
SafeWriter dbg;
|
||||
dbg.init();
|
||||
|
|
@ -510,8 +551,10 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
}
|
||||
w->writeC('\n');
|
||||
if (totalSize>firstBankSize) {
|
||||
lastError="first bank is not large enough to contain call table";
|
||||
return NULL;
|
||||
logAppend("ERROR: first bank is not large enough to contain call table");
|
||||
failed=true;
|
||||
running=false;
|
||||
return;
|
||||
}
|
||||
|
||||
int curBank=0;
|
||||
|
|
@ -572,13 +615,50 @@ SafeWriter* DivEngine::saveTiuna(const bool* sysToExport, const char* baseLabel,
|
|||
}
|
||||
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);
|
||||
//}
|
||||
logAppendf("total size: %d bytes (%d banks)",totalSize,curBank+1);
|
||||
|
||||
return w;
|
||||
output.push_back(DivROMExportOutput("export.asm",w));
|
||||
|
||||
logAppend("finished!");
|
||||
|
||||
running=false;
|
||||
}
|
||||
|
||||
bool DivExportTiuna::go(DivEngine* eng) {
|
||||
progress[0].name="Compression";
|
||||
progress[0].amount=0.0f;
|
||||
progress[1].name="Confirmed Matches";
|
||||
progress[1].amount=0.0f;
|
||||
|
||||
e=eng;
|
||||
running=true;
|
||||
failed=false;
|
||||
mustAbort=false;
|
||||
exportThread=new std::thread(&DivExportTiuna::run,this);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DivExportTiuna::wait() {
|
||||
if (exportThread!=NULL) {
|
||||
exportThread->join();
|
||||
delete exportThread;
|
||||
}
|
||||
}
|
||||
|
||||
void DivExportTiuna::abort() {
|
||||
mustAbort=true;
|
||||
wait();
|
||||
}
|
||||
|
||||
bool DivExportTiuna::isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
bool DivExportTiuna::hasFailed() {
|
||||
return failed;
|
||||
}
|
||||
|
||||
DivROMExportProgress DivExportTiuna::getProgress(int index) {
|
||||
if (index<0 || index>2) return progress[2];
|
||||
return progress[index];
|
||||
}
|
||||
38
src/engine/export/tiuna.h
Normal file
38
src/engine/export/tiuna.h
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* 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 "../export.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
class DivExportTiuna: public DivROMExport {
|
||||
DivEngine* e;
|
||||
std::thread* exportThread;
|
||||
DivROMExportProgress progress[3];
|
||||
bool running, failed, mustAbort;
|
||||
void run();
|
||||
public:
|
||||
bool go(DivEngine* e);
|
||||
bool isRunning();
|
||||
bool hasFailed();
|
||||
void abort();
|
||||
void wait();
|
||||
DivROMExportProgress getProgress(int index=0);
|
||||
~DivExportTiuna() {}
|
||||
};
|
||||
63
src/engine/exportDef.cpp
Normal file
63
src/engine/exportDef.cpp
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/**
|
||||
* 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 "engine.h"
|
||||
|
||||
DivROMExportDef* DivEngine::romExportDefs[DIV_ROM_MAX];
|
||||
|
||||
const DivROMExportDef* DivEngine::getROMExportDef(DivROMExportOptions opt) {
|
||||
return romExportDefs[opt];
|
||||
}
|
||||
|
||||
void DivEngine::registerROMExports() {
|
||||
logD("registering ROM exports...");
|
||||
|
||||
romExportDefs[DIV_ROM_AMIGA_VALIDATION]=new DivROMExportDef(
|
||||
"Amiga Validation", "tildearrow",
|
||||
"a test export for ensuring Amiga emulation is accurate. do not use!",
|
||||
NULL, NULL,
|
||||
{DIV_SYSTEM_AMIGA},
|
||||
true, DIV_REQPOL_EXACT
|
||||
);
|
||||
|
||||
romExportDefs[DIV_ROM_ZSM]=new DivROMExportDef(
|
||||
"Commander X16 ZSM", "ZeroByteOrg and MooingLemur",
|
||||
"Commander X16 Zsound Music File.\n"
|
||||
"for use with Melodius, Calliope and/or ZSMKit:\n"
|
||||
"- https://github.com/mooinglemur/zsmkit (development)\n"
|
||||
"- https://github.com/mooinglemur/melodius (player)\n"
|
||||
"- https://github.com/ZeroByteOrg/calliope (player)\n",
|
||||
"ZSM file", ".zsm",
|
||||
{
|
||||
DIV_SYSTEM_YM2151, DIV_SYSTEM_VERA
|
||||
},
|
||||
false, DIV_REQPOL_LAX
|
||||
);
|
||||
|
||||
romExportDefs[DIV_ROM_TIUNA]=new DivROMExportDef(
|
||||
"Atari 2600 (TIunA)", "Natt Akuma",
|
||||
"advanced driver with software tuning support.\n"
|
||||
"see https://github.com/AYCEdemo/twin-tiuna for code.",
|
||||
"assembly files", ".asm",
|
||||
{
|
||||
DIV_SYSTEM_TIA
|
||||
},
|
||||
false, DIV_REQPOL_ANY
|
||||
);
|
||||
}
|
||||
|
|
@ -2094,6 +2094,12 @@ bool DivEngine::loadFur(unsigned char* file, size_t len, int variantID) {
|
|||
ds.systemFlags[i].set("oldPitch",true);
|
||||
}
|
||||
}
|
||||
} else if (ds.version<217) {
|
||||
for (int i=0; i<ds.systemLen; i++) {
|
||||
if (ds.system[i]==DIV_SYSTEM_VERA) {
|
||||
ds.systemFlags[i].set("chipType",1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (active) quitDispatch();
|
||||
|
|
|
|||
|
|
@ -639,6 +639,8 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
logD("seek not needed...");
|
||||
}
|
||||
|
||||
logV("reading sample data (%d)",s->samples);
|
||||
|
||||
if (flags&8) { // compressed sample
|
||||
unsigned int ret=0;
|
||||
logV("decompression begin... (%d)",s->samples);
|
||||
|
|
@ -672,62 +674,66 @@ bool DivEngine::loadIT(unsigned char* file, size_t len) {
|
|||
}
|
||||
logV("got: %d",ret);
|
||||
} else {
|
||||
if (s->depth==DIV_SAMPLE_DEPTH_16BIT) {
|
||||
if (flags&4) { // downmix stereo
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
short l;
|
||||
if (convert&2) {
|
||||
l=reader.readS_BE();
|
||||
} else {
|
||||
l=reader.readS();
|
||||
try {
|
||||
if (s->depth==DIV_SAMPLE_DEPTH_16BIT) {
|
||||
if (flags&4) { // downmix stereo
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
short l;
|
||||
if (convert&2) {
|
||||
l=reader.readS_BE();
|
||||
} else {
|
||||
l=reader.readS();
|
||||
}
|
||||
if (!(convert&1)) {
|
||||
l^=0x8000;
|
||||
}
|
||||
s->data16[i]=l;
|
||||
}
|
||||
if (!(convert&1)) {
|
||||
l^=0x8000;
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
short r;
|
||||
if (convert&2) {
|
||||
r=reader.readS_BE();
|
||||
} else {
|
||||
r=reader.readS();
|
||||
}
|
||||
if (!(convert&1)) {
|
||||
r^=0x8000;
|
||||
}
|
||||
s->data16[i]=(s->data16[i]+r)>>1;
|
||||
}
|
||||
s->data16[i]=l;
|
||||
}
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
short r;
|
||||
if (convert&2) {
|
||||
r=reader.readS_BE();
|
||||
} else {
|
||||
r=reader.readS();
|
||||
} else {
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
if (convert&2) {
|
||||
s->data16[i]=reader.readS_BE()^((convert&1)?0:0x8000);
|
||||
} else {
|
||||
s->data16[i]=reader.readS()^((convert&1)?0:0x8000);
|
||||
}
|
||||
}
|
||||
if (!(convert&1)) {
|
||||
r^=0x8000;
|
||||
}
|
||||
s->data16[i]=(s->data16[i]+r)>>1;
|
||||
}
|
||||
} else {
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
if (convert&2) {
|
||||
s->data16[i]=reader.readS_BE()^((convert&1)?0:0x8000);
|
||||
} else {
|
||||
s->data16[i]=reader.readS()^((convert&1)?0:0x8000);
|
||||
if (flags&4) { // downmix stereo
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
signed char l=reader.readC();
|
||||
if (!(convert&1)) {
|
||||
l^=0x80;
|
||||
}
|
||||
s->data8[i]=l;
|
||||
}
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
signed char r=reader.readC();
|
||||
if (!(convert&1)) {
|
||||
r^=0x80;
|
||||
}
|
||||
s->data8[i]=(s->data8[i]+r)>>1;
|
||||
}
|
||||
} else {
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
s->data8[i]=reader.readC()^((convert&1)?0:0x80);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (flags&4) { // downmix stereo
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
signed char l=reader.readC();
|
||||
if (!(convert&1)) {
|
||||
l^=0x80;
|
||||
}
|
||||
s->data8[i]=l;
|
||||
}
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
signed char r=reader.readC();
|
||||
if (!(convert&1)) {
|
||||
r^=0x80;
|
||||
}
|
||||
s->data8[i]=(s->data8[i]+r)>>1;
|
||||
}
|
||||
} else {
|
||||
for (unsigned int i=0; i<s->samples; i++) {
|
||||
s->data8[i]=reader.readC()^((convert&1)?0:0x80);
|
||||
}
|
||||
}
|
||||
} catch (EndOfFileException& e) {
|
||||
logW("premature end of file...");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ static void readSbiOpData(sbi_t& sbi, SafeReader& reader) {
|
|||
bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
||||
struct InvalidHeaderException {};
|
||||
bool success=false;
|
||||
bool opl2=!getConfInt("s3mOPL3",0);
|
||||
char magic[4]={0,0,0,0};
|
||||
SafeReader reader=SafeReader(file,len);
|
||||
warnings="";
|
||||
|
|
@ -273,11 +274,16 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
|||
bool hasPCM=false;
|
||||
bool hasFM=false;
|
||||
int numChans=0;
|
||||
int realNumChans=0;
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
if (chanSettings[i]==255) continue;
|
||||
if ((chanSettings[i]&127)>=32) continue;
|
||||
if ((chanSettings[i]&127)>=16) {
|
||||
for (int ch=0; ch<32; ch++) {
|
||||
if (chanSettings[ch]!=255) realNumChans++;
|
||||
}
|
||||
|
||||
for (int ch=0; ch<32; ch++) {
|
||||
if (chanSettings[ch]==255) continue;
|
||||
if ((chanSettings[ch]&127)>=32) continue;
|
||||
if ((chanSettings[ch]&127)>=16) {
|
||||
hasFM=true;
|
||||
} else {
|
||||
hasPCM=true;
|
||||
|
|
@ -287,34 +293,69 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
|||
if (hasFM && hasPCM) break;
|
||||
}
|
||||
|
||||
int pcmChan=hasFM?9:0;
|
||||
int pcmChan=hasFM?(opl2 ? 9 : 18):0;
|
||||
int fmChan=hasPCM?32:0;
|
||||
int invalidChan=40;
|
||||
|
||||
for (int i=0; i<32; i++) {
|
||||
if (chanSettings[i]==255) {
|
||||
chanMap[i]=invalidChan++;
|
||||
for (int ch=0; ch<32; ch++) {
|
||||
if (chanSettings[ch]==255) {
|
||||
chanMap[ch]=invalidChan++;
|
||||
continue;
|
||||
}
|
||||
if ((chanSettings[i]&127)>=32) {
|
||||
chanMap[i]=invalidChan++;
|
||||
if ((chanSettings[ch]&127)>=32) {
|
||||
chanMap[ch]=invalidChan++;
|
||||
continue;
|
||||
}
|
||||
if ((chanSettings[i]&127)>=16) {
|
||||
chanMap[i]=fmChan++;
|
||||
if ((chanSettings[ch]&127)>=16) {
|
||||
chanMap[ch]=fmChan++;
|
||||
} else {
|
||||
chanMap[i]=pcmChan++;
|
||||
chanMap[ch]=pcmChan++;
|
||||
}
|
||||
}
|
||||
|
||||
char buffer[40];
|
||||
int chanIndex = 1;
|
||||
|
||||
if (hasPCM) {
|
||||
for (int i=pcmChan; i<32; i++) {
|
||||
ds.subsong[0]->chanShow[i]=false;
|
||||
ds.subsong[0]->chanShowChanOsc[i]=false;
|
||||
for(int ch = 0; ch < pcmChan - (realNumChans - (hasFM ? 9 : 0)); ch++)
|
||||
{
|
||||
ds.subsong[0]->chanShow[ch]=false;
|
||||
ds.subsong[0]->chanShowChanOsc[ch]=false;
|
||||
}
|
||||
|
||||
for (int ch=pcmChan; ch<32; ch++) {
|
||||
ds.subsong[0]->chanShow[ch]=false;
|
||||
ds.subsong[0]->chanShowChanOsc[ch]=false;
|
||||
}
|
||||
|
||||
for(int ch = 0; ch < 32; ch++)
|
||||
{
|
||||
if(ds.subsong[0]->chanShow[ch])
|
||||
{
|
||||
snprintf(buffer, 40, _("Channel %d"), chanIndex);
|
||||
ds.subsong[0]->chanName[ch] = buffer;
|
||||
chanIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasFM && !opl2) {
|
||||
for (int ch=(hasPCM?32:0) + 9; ch<(hasPCM?32:0) + 18; ch++) {
|
||||
ds.subsong[0]->chanShow[ch]=false;
|
||||
ds.subsong[0]->chanShowChanOsc[ch]=false;
|
||||
}
|
||||
|
||||
chanIndex = 1;
|
||||
|
||||
for (int ch=(hasPCM?32:0); ch<(hasPCM?32:0) + 9; ch++) {
|
||||
snprintf(buffer, 40, _("FM %d"), chanIndex);
|
||||
ds.subsong[0]->chanName[ch] = buffer;
|
||||
chanIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
logV("numChans: %d",numChans);
|
||||
logV("realNumChans: %d",realNumChans);
|
||||
|
||||
ds.systemName="PC";
|
||||
if (hasPCM) {
|
||||
|
|
@ -327,7 +368,7 @@ bool DivEngine::loadS3M(unsigned char* file, size_t len) {
|
|||
ds.systemLen++;
|
||||
}
|
||||
if (hasFM) {
|
||||
ds.system[ds.systemLen]=DIV_SYSTEM_OPL2;
|
||||
ds.system[ds.systemLen]=opl2 ? DIV_SYSTEM_OPL2 : DIV_SYSTEM_OPL3;
|
||||
ds.systemVol[ds.systemLen]=1.0f;
|
||||
ds.systemPan[ds.systemLen]=0;
|
||||
ds.systemLen++;
|
||||
|
|
|
|||
|
|
@ -155,43 +155,76 @@ void DivPlatformAY8910::runDAC() {
|
|||
}
|
||||
|
||||
void DivPlatformAY8910::runTFX() {
|
||||
if (selCore) return;
|
||||
/*
|
||||
developer's note: if you are checking for intellivision
|
||||
make sure to add "&& selCore"
|
||||
because for some reason, the register remap doesn't work
|
||||
when the user uses AtomicSSG core
|
||||
*/
|
||||
int timerPeriod, output;
|
||||
for (int i=0; i<3; i++) {
|
||||
if (chan[i].active && (chan[i].curPSGMode.val&16) && !(chan[i].curPSGMode.val&8) && chan[i].tfx.mode!=-1) {
|
||||
if (chan[i].tfx.mode == -1 && !isMuted[i]) {
|
||||
/*
|
||||
bug: if in the timer FX macro the user enables
|
||||
and then disables PWM while there is no volume macro
|
||||
there is now a random chance that the resulting output
|
||||
is silent or has volume set incorrectly
|
||||
i've tried to implement a fix, but it seems to be
|
||||
ineffective, so...
|
||||
TODO: actually implement a proper fix
|
||||
*/
|
||||
if (intellivision && chan[i].curPSGMode.getEnvelope()) {
|
||||
immWrite(0x08+i,(chan[i].outVol&0xc)<<2);
|
||||
continue;
|
||||
} else {
|
||||
immWrite(0x08+i,(chan[i].outVol&15)|((chan[i].curPSGMode.getEnvelope())<<2));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
chan[i].tfx.counter += 1;
|
||||
if (chan[i].tfx.counter >= chan[i].tfx.period && chan[i].tfx.mode == 0) {
|
||||
chan[i].tfx.counter = 0;
|
||||
chan[i].tfx.out ^= 1;
|
||||
output = MAX(0, ((chan[i].tfx.out) ? (chan[i].outVol&15) : (chan[i].tfx.lowBound-(15-chan[i].outVol))));
|
||||
output &= 15;
|
||||
output = ((chan[i].tfx.out) ? chan[i].outVol : (chan[i].tfx.lowBound-(15-chan[i].outVol)));
|
||||
// TODO: fix this stupid crackling noise that happens
|
||||
// everytime the volume changes
|
||||
output = (output <= 0) ? 0 : output; // underflow
|
||||
output = (output >= 15) ? 15 : output; // overflow
|
||||
output &= 15; // i don't know if i need this but i'm too scared to remove it
|
||||
if (!isMuted[i]) {
|
||||
immWrite(0x08+i,output|(chan[i].curPSGMode.getEnvelope()<<2));
|
||||
if (intellivision && selCore) {
|
||||
immWrite(0x0b+i,(output&0xc)<<2);
|
||||
} else {
|
||||
immWrite(0x08+i,output|(chan[i].curPSGMode.getEnvelope()<<2));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chan[i].tfx.counter >= chan[i].tfx.period && chan[i].tfx.mode == 1) {
|
||||
chan[i].tfx.counter = 0;
|
||||
if (!isMuted[i]) {
|
||||
immWrite(0xd, ayEnvMode);
|
||||
if (intellivision && selCore) {
|
||||
immWrite(0xa, ayEnvMode);
|
||||
} else {
|
||||
immWrite(0xd, ayEnvMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chan[i].tfx.counter >= chan[i].tfx.period && chan[i].tfx.mode == 2) {
|
||||
chan[i].tfx.counter = 0;
|
||||
}
|
||||
if (chan[i].tfx.mode == -1 && !isMuted[i]) {
|
||||
if (intellivision && chan[i].curPSGMode.getEnvelope()) {
|
||||
immWrite(0x08+i,(chan[i].outVol&0xc)<<2);
|
||||
} else {
|
||||
immWrite(0x08+i,(chan[i].outVol&15)|((chan[i].curPSGMode.getEnvelope())<<2));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (chan[i].tfx.num > 0) {
|
||||
timerPeriod = chan[i].freq*chan[i].tfx.den/chan[i].tfx.num;
|
||||
} else {
|
||||
timerPeriod = chan[i].freq*chan[i].tfx.den;
|
||||
}
|
||||
timerPeriod = chan[i].freq*chan[i].tfx.den/chan[i].tfx.num;
|
||||
} else {
|
||||
timerPeriod = chan[i].freq*chan[i].tfx.den;
|
||||
}
|
||||
if (chan[i].tfx.num > 0 && chan[i].tfx.den > 0) chan[i].tfx.period=timerPeriod+chan[i].tfx.offset;
|
||||
// stupid pitch correction because:
|
||||
// YM2149 half-clock and Sunsoft 5B: timers run an octave too high
|
||||
// on AtomicSSG core timers run 2 octaves too high
|
||||
if (clockSel || sunsoft) chan[i].tfx.period = chan[i].tfx.period * 2;
|
||||
if (selCore) chan[i].tfx.period = chan[i].tfx.period * 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -388,6 +421,7 @@ void DivPlatformAY8910::tick(bool sysTick) {
|
|||
if (chan[i].std.phaseReset.had) {
|
||||
if (chan[i].std.phaseReset.val==1) {
|
||||
chan[i].tfx.counter = 0;
|
||||
chan[i].tfx.out = 0;
|
||||
if (chan[i].nextPSGMode.val&8) {
|
||||
if (dumpWrites) addWrite(0xffff0002+(i<<8),0);
|
||||
if (chan[i].dac.sample<0 || chan[i].dac.sample>=parent->song.sampleLen) {
|
||||
|
|
@ -726,12 +760,10 @@ int DivPlatformAY8910::dispatch(DivCommand c) {
|
|||
break;
|
||||
}
|
||||
case DIV_CMD_STD_NOISE_MODE:
|
||||
if (c.value&0xf0 && !(chan[c.chan].nextPSGMode.val&8)) {
|
||||
chan[c.chan].nextPSGMode.val|=16;
|
||||
chan[c.chan].tfx.mode = (c.value&3);
|
||||
}
|
||||
if (!(chan[c.chan].nextPSGMode.val&8)) {
|
||||
if (c.value<16) {
|
||||
chan[c.chan].nextPSGMode.val|=16;
|
||||
chan[c.chan].tfx.mode=(((c.value&0xf0)>>4)&3)-1;
|
||||
if ((c.value&15)<16) {
|
||||
chan[c.chan].nextPSGMode.val=(c.value+1)&7;
|
||||
chan[c.chan].nextPSGMode.val|=chan[c.chan].curPSGMode.val&16;
|
||||
if (chan[c.chan].active) {
|
||||
|
|
@ -805,9 +837,16 @@ int DivPlatformAY8910::dispatch(DivCommand c) {
|
|||
updateOutSel(true);
|
||||
immWrite(14+(c.value?1:0),(c.value?portBVal:portAVal));
|
||||
break;
|
||||
case DIV_CMD_AY_AUTO_PWM:
|
||||
chan[c.chan].tfx.offset=c.value;
|
||||
case DIV_CMD_AY_NOISE_MASK_AND:
|
||||
chan[c.chan].tfx.num=c.value>>4;
|
||||
chan[c.chan].tfx.den=c.value&15;
|
||||
break;
|
||||
case DIV_CMD_AY_AUTO_PWM: {
|
||||
// best way i could find to do signed :/
|
||||
signed char signVal=c.value;
|
||||
chan[c.chan].tfx.offset=signVal;
|
||||
break;
|
||||
}
|
||||
case DIV_CMD_SAMPLE_MODE:
|
||||
if (c.value>0) {
|
||||
chan[c.chan].nextPSGMode.val|=8;
|
||||
|
|
|
|||
|
|
@ -39,14 +39,25 @@ const char** DivPlatformMSM6295::getRegisterSheet() {
|
|||
}
|
||||
|
||||
u8 DivPlatformMSM6295::read_byte(u32 address) {
|
||||
if (adpcmMem==NULL || address>=getSampleMemCapacity(0)) {
|
||||
if (adpcmMem==NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (isBanked) {
|
||||
if (address<0x400) {
|
||||
return adpcmMem[(bank[(address>>8)&0x3]<<16)|(address&0x3ff)];
|
||||
unsigned int bankedAddress=(bank[(address>>8)&0x3]<<16)|(address&0x3ff);
|
||||
if (bankedAddress>=getSampleMemCapacity(0)) {
|
||||
return 0;
|
||||
}
|
||||
return adpcmMem[bankedAddress&0xffffff];
|
||||
}
|
||||
return adpcmMem[(bank[(address>>16)&0x3]<<16)|(address&0xffff)];
|
||||
unsigned int bankedAddress=(bank[(address>>16)&0x3]<<16)|(address&0xffff);
|
||||
if (bankedAddress>=getSampleMemCapacity(0)) {
|
||||
return 0;
|
||||
}
|
||||
return adpcmMem[bankedAddress&0xffffff];
|
||||
}
|
||||
if (address>=getSampleMemCapacity(0)) {
|
||||
return 0;
|
||||
}
|
||||
return adpcmMem[address&0x3ffff];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
// Chip revisions
|
||||
// 0: V 0.3.0
|
||||
// 1: V 47.0.0 (9-bit volume, phase reset on mute)
|
||||
// 2: V 47.0.2 (Pulse Width XOR on Saw and Triangle)
|
||||
|
||||
#include "vera_psg.h"
|
||||
|
||||
|
|
@ -88,8 +89,8 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right)
|
|||
uint8_t v = 0;
|
||||
switch (ch->waveform) {
|
||||
case WF_PULSE: v = (ch->phase >> 10) > ch->pw ? 0 : 63; break;
|
||||
case WF_SAWTOOTH: v = ch->phase >> 11; break;
|
||||
case WF_TRIANGLE: v = (ch->phase & 0x10000) ? (~(ch->phase >> 10) & 0x3F) : ((ch->phase >> 10) & 0x3F); break;
|
||||
case WF_SAWTOOTH: v = (ch->phase >> 11) ^ (psg->chipType < 2 ? 0 : (ch->pw ^ 0x3f) & 0x3f); break;
|
||||
case WF_TRIANGLE: v = ((ch->phase & 0x10000) ? (~(ch->phase >> 10) & 0x3F) : ((ch->phase >> 10) & 0x3F)) ^ (psg->chipType < 2 ? 0 : (ch->pw ^ 0x3f) & 0x3f); break;
|
||||
case WF_NOISE: v = ch->noiseval; break;
|
||||
}
|
||||
int8_t sv = (v ^ 0x20);
|
||||
|
|
|
|||
|
|
@ -532,7 +532,7 @@ void DivPlatformVERA::poke(std::vector<DivRegWrite>& wlist) {
|
|||
}
|
||||
|
||||
void DivPlatformVERA::setFlags(const DivConfig& flags) {
|
||||
psg->chipType=flags.getInt("chipType",1);
|
||||
psg->chipType=flags.getInt("chipType",2);
|
||||
chipClock=25000000;
|
||||
CHECK_CUSTOM_CLOCK;
|
||||
rate=chipClock/512;
|
||||
|
|
|
|||
|
|
@ -1647,26 +1647,34 @@ bool DivEngine::nextTick(bool noAccum, bool inhibitLowLat) {
|
|||
chan[i].panPos+=chan[i].panRate;
|
||||
chan[i].panPos&=255;
|
||||
|
||||
// calculate...
|
||||
// calculate inverted...
|
||||
switch (chan[i].panPos&0xc0) {
|
||||
case 0: // center -> right
|
||||
chan[i].panL=0xff-((chan[i].panPos&0x3f)<<2);
|
||||
chan[i].panR=0xff;
|
||||
chan[i].panL=((chan[i].panPos&0x3f)<<2);
|
||||
chan[i].panR=0;
|
||||
break;
|
||||
case 0x40: // right -> center
|
||||
chan[i].panL=(chan[i].panPos&0x3f)<<2;
|
||||
chan[i].panR=0xff;
|
||||
chan[i].panL=0xff-((chan[i].panPos&0x3f)<<2);
|
||||
chan[i].panR=0;
|
||||
break;
|
||||
case 0x80: // center -> left
|
||||
chan[i].panL=0xff;
|
||||
chan[i].panR=0xff-((chan[i].panPos&0x3f)<<2);
|
||||
chan[i].panL=0;
|
||||
chan[i].panR=((chan[i].panPos&0x3f)<<2);
|
||||
break;
|
||||
case 0xc0: // left -> center
|
||||
chan[i].panL=0xff;
|
||||
chan[i].panR=(chan[i].panPos&0x3f)<<2;
|
||||
chan[i].panL=0;
|
||||
chan[i].panR=0xff-((chan[i].panPos&0x3f)<<2);
|
||||
break;
|
||||
}
|
||||
|
||||
// multiply by depth
|
||||
chan[i].panL=(chan[i].panL*chan[i].panDepth)/15;
|
||||
chan[i].panR=(chan[i].panR*chan[i].panDepth)/15;
|
||||
|
||||
// then invert it to get final panning
|
||||
chan[i].panL^=0xff;
|
||||
chan[i].panR^=0xff;
|
||||
|
||||
dispatchCmd(DivCommand(DIV_CMD_PANNING,i,chan[i].panL,chan[i].panR));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,6 +141,8 @@ enum DivSystem {
|
|||
DIV_SYSTEM_5E01,
|
||||
DIV_SYSTEM_BIFURCATOR,
|
||||
DIV_SYSTEM_SID2,
|
||||
|
||||
DIV_SYSTEM_MAX
|
||||
};
|
||||
|
||||
enum DivEffectType: unsigned short {
|
||||
|
|
|
|||
|
|
@ -433,6 +433,7 @@ void DivEngine::registerSystems() {
|
|||
{0x25, {DIV_CMD_AY_ENVELOPE_SLIDE, _("25xx: Envelope slide up"), negEffectVal}},
|
||||
{0x26, {DIV_CMD_AY_ENVELOPE_SLIDE, _("26xx: Envelope slide down")}},
|
||||
{0x29, {DIV_CMD_AY_AUTO_ENVELOPE, _("29xy: Set auto-envelope (x: numerator; y: denominator)")}},
|
||||
{0x2c, {DIV_CMD_AY_AUTO_PWM, _("2Cxx: Set timer period offset (bit 7: sign)")}},
|
||||
{0x2e, {DIV_CMD_AY_IO_WRITE, _("2Exx: Write to I/O port A"), constVal<0>, effectVal}},
|
||||
{0x2f, {DIV_CMD_AY_IO_WRITE, _("2Fxx: Write to I/O port B"), constVal<1>, effectVal}},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -133,14 +133,6 @@ void DivZSM::writePSG(unsigned char a, unsigned char v) {
|
|||
} else if (a>=64) {
|
||||
return writePCM(a-64,v);
|
||||
}
|
||||
if (optimize) {
|
||||
if ((a&3)==3 && v>64) {
|
||||
// Pulse width on non-pulse waves is nonsense and wasteful
|
||||
// No need to preserve state here because the next write that
|
||||
// selects pulse will also set the pulse width in this register
|
||||
v&=0xc0;
|
||||
}
|
||||
}
|
||||
if (psgState[psg_PREV][a]==v) {
|
||||
if (psgState[psg_NEW][a]!=v) {
|
||||
// NEW value is being reset to the same as PREV value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue