diff --git a/CMakeLists.txt b/CMakeLists.txt index 198b52a1e..95ee1fbc9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -706,6 +706,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 diff --git a/src/engine/engine.h b/src/engine/engine.h index 925bd043c..7590e7315 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -700,6 +700,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 diff --git a/src/engine/fileOps/fur.cpp b/src/engine/fileOps/fur.cpp index 9c65963c7..0251c410e 100644 --- a/src/engine/fileOps/fur.cpp +++ b/src/engine/fileOps/fur.cpp @@ -2084,11 +2084,15 @@ 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=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 (clock31) 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; } diff --git a/src/engine/platform/tia.h b/src/engine/platform/tia.h index a66de9cbd..27b4c7c7a 100644 --- a/src/engine/platform/tia.h +++ b/src/engine/platform/tia.h @@ -27,21 +27,31 @@ class DivPlatformTIA: public DivDispatch { protected: struct Channel: public SharedChannel { unsigned char shape; + unsigned char curFreq, tuneCtr, tuneFreq; + int tuneAcc; Channel(): SharedChannel(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); diff --git a/src/engine/tiunaOps.cpp b/src/engine/tiunaOps.cpp new file mode 100644 index 000000000..1f63129ec --- /dev/null +++ b/src/engine/tiunaOps.cpp @@ -0,0 +1,521 @@ +/** + * 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 +#include +#include +#include +#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 pos; +}; + +static void writeCmd(std::vector& cmds, TiunaCmd& cmd, unsigned char ch, int& lastWait, int fromTick, int toTick) { + while (fromTick=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; itoggleRegisterDump(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; + int lastEngineTicks=-1; + TiunaLast last[2]; + TiunaNew news[2]; + std::map 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& 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; + 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; + } + lastEngineTicks=ticks; + cmdStream.clear(); + tick++; + } + for (int i=0; igetRegisterWrites().clear(); + disCont[i].dispatch->toggleRegisterDump(false); + } + + remainingLoops=-1; + playing=false; + freelance=false; + extValuePresent=false; + BUSY_END; + + // render commands + std::vector 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 confirmedMatches; + std::vector callTicks; + int cmId=0; + int cmdSize=renderedCmds.size(); + std::vector processed=std::vector(cmdSize,false); + while (firstBankSize>768 && cmId<(MAX(firstBankSize/1024,1))*256) { + bool hasMatch=false; + std::map potentialMatches; + for (int i=0; i=cmdSize-1) break; + std::vector match; + int ch=renderedCmds[i].ch; + for (int j=i+1; j=cmdSize) break; + int k=0; + int ticks=0; + int size=0; + while ( + (i+k)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.pos256 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; iwriteText(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; jwriteText(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; jwriteText(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; jwriteText(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; jwriteText(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 callVisited=std::vector(cmIdLen,false); + auto cmIter=confirmedMatches.begin(); + for (int i=0; ipos)); + if (cmIter!=confirmedMatches.end() && i==cmIter->pos) { + if (cmIter->idid]) { + 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; jwriteText(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; +} diff --git a/src/gui/exportOptions.cpp b/src/gui/exportOptions.cpp index 47710d327..02d0ef045 100644 --- a/src/gui/exportOptions.cpp +++ b/src/gui/exportOptions.cpp @@ -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; isong.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; isong.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; isong.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; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 07bd90d74..31cbd3544 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -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), diff --git a/src/gui/gui.h b/src/gui/gui.h index 009c480ab..905d511d9 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -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); diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index a9b13113e..6ba934ab0 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -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, "") diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index e9f46f1a1..d65fb72f7 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -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;