From 76cdc3a6a549eeff64ed57319e7ed3157149708d Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 8 Dec 2022 14:18:22 +0900 Subject: [PATCH 01/36] (Partially) K007232 support Chip ID is placeholder. --- CMakeLists.txt | 1 + papers/doc/6-sample/README.md | 1 + papers/doc/7-systems/README.md | 1 + papers/doc/7-systems/k007232.md | 9 + papers/format.md | 4 + src/engine/dispatchContainer.cpp | 4 + src/engine/fileOps.cpp | 3 + src/engine/instrument.cpp | 4 + src/engine/instrument.h | 1 + src/engine/platform/k007232.cpp | 541 +++++++++++++++++++++++++++++++ src/engine/platform/k007232.h | 130 ++++++++ src/engine/song.h | 1 + src/engine/sysDef.cpp | 10 + src/gui/dataList.cpp | 4 + src/gui/doAction.cpp | 3 +- src/gui/gui.h | 1 + src/gui/guiConst.cpp | 4 + src/gui/insEdit.cpp | 11 +- src/gui/presets.cpp | 5 + src/gui/settings.cpp | 1 + src/gui/sysConf.cpp | 14 + 21 files changed, 748 insertions(+), 5 deletions(-) create mode 100644 papers/doc/7-systems/k007232.md create mode 100644 src/engine/platform/k007232.cpp create mode 100644 src/engine/platform/k007232.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b6b92df9..68f42e274 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -524,6 +524,7 @@ src/engine/platform/ymz280b.cpp src/engine/platform/namcowsg.cpp src/engine/platform/rf5c68.cpp src/engine/platform/snes.cpp +src/engine/platform/k007232.cpp src/engine/platform/pcmdac.cpp src/engine/platform/dummy.cpp ) diff --git a/papers/doc/6-sample/README.md b/papers/doc/6-sample/README.md index 4fbb6c914..ec6f230a6 100644 --- a/papers/doc/6-sample/README.md +++ b/papers/doc/6-sample/README.md @@ -25,6 +25,7 @@ as of Furnace 0.6, the following sound chips have sample support: - tildearrow Sound Unit - VERA (last channel only) - Y8950 (last channel only) +- Konami K007232 - a few more that I've forgotten to mention ## compatible sample mode diff --git a/papers/doc/7-systems/README.md b/papers/doc/7-systems/README.md index 1ec5aa305..29c08c2ee 100644 --- a/papers/doc/7-systems/README.md +++ b/papers/doc/7-systems/README.md @@ -12,6 +12,7 @@ this is a list of sound chips that Furnace supports, including effects. - [Generic PCM DAC](dac.md) - [Famicom Disk System](fds.md) - [Game Boy](game-boy.md) +- [Konami K007232](k007232.md) - [Konami SCC](scc.md) - [Konami VRC6](vrc6.md) - [Atari Lynx](lynx.md) diff --git a/papers/doc/7-systems/k007232.md b/papers/doc/7-systems/k007232.md new file mode 100644 index 000000000..92b4759c4 --- /dev/null +++ b/papers/doc/7-systems/k007232.md @@ -0,0 +1,9 @@ +# Konami K007232 + +a Konami's 2 channel PCM sound chip was used in their arcade boards in 1986-1990. + +Its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). + +# effects + +- Nothing for now diff --git a/papers/format.md b/papers/format.md index e29b12891..492544ec5 100644 --- a/papers/format.md +++ b/papers/format.md @@ -1626,6 +1626,10 @@ chips which aren't on this list don't have any flags. - bit 16-19: outDepth (int) - bit 20: stereo (bool) +## (Placeholder): Konami K007232 + +- bit 0: stereo (bool) + ## 0xe0: QSound - bit 0-11: echoDelay (int) diff --git a/src/engine/dispatchContainer.cpp b/src/engine/dispatchContainer.cpp index 25055a900..3215914a8 100644 --- a/src/engine/dispatchContainer.cpp +++ b/src/engine/dispatchContainer.cpp @@ -70,6 +70,7 @@ #include "platform/rf5c68.h" #include "platform/snes.h" #include "platform/vb.h" +#include "platform/k007232.h" #include "platform/pcmdac.h" #include "platform/dummy.h" #include "../ta-log.h" @@ -418,6 +419,9 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do case DIV_SYSTEM_SNES: dispatch=new DivPlatformSNES; break; + case DIV_SYSTEM_K007232: + dispatch=new DivPlatformK007232; + break; case DIV_SYSTEM_PCM_DAC: dispatch=new DivPlatformPCMDAC; break; diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index e01a57101..32cd0dcfe 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -1571,6 +1571,9 @@ void DivEngine::convertOldFlags(unsigned int oldFlags, DivConfig& newFlags, DivS newFlags.set("echoDelay",(int)(oldFlags&0xfff)); newFlags.set("echoFeedback",(int)((oldFlags>>12)&255)); break; + case DIV_SYSTEM_K007232: + if (oldFlags&1) newFlags.set("stereo",true); + break; default: break; } diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index dc991f6ad..76168173f 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -911,6 +911,10 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song) { break; case DIV_INS_T6W28: break; + case DIV_INS_K007232: + featureSM=true; + featureSL=true; + break; case DIV_INS_MAX: break; diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 829223f22..a4c1effc8 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -75,6 +75,7 @@ enum DivInstrumentType: unsigned short { DIV_INS_RF5C68=42, DIV_INS_MSM5232=43, DIV_INS_T6W28=44, + DIV_INS_K007232=45, DIV_INS_MAX, DIV_INS_NULL }; diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp new file mode 100644 index 000000000..6dee42356 --- /dev/null +++ b/src/engine/platform/k007232.cpp @@ -0,0 +1,541 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 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 "k007232.h" +#include "../engine.h" +#include "../../ta-log.h" +#include + +#define rWrite(a,v) {if(!skipRegisterWrites) {writes.emplace(a,v); if(dumpWrites) addWrite(a,v);}} + +#define CHIP_DIVIDER 64 + +const char* regCheatSheetK007232[]={ + // on-chip + "CHX_FreqL", "X*6+0", + "CHX_FreqH", "X*6+1", + "CHX_StartL", "X*6+2", + "CHX_StartM", "X*6+3", + "CHX_StartH", "X*6+4", + "CHX_Keyon", "X*6+5", + "SLEV", "C", // external IO + "Loop", "D", + // off-chip + "CHX_Volume", "X*2+10", + "CHX_Bank", "X*2+12", + NULL +}; + +const char** DivPlatformK007232::getRegisterSheet() { + return regCheatSheetK007232; +} + +inline void DivPlatformK007232::chWrite(unsigned char ch, unsigned int addr, unsigned char val) { + if (!skipRegisterWrites) { + if ((ch<2) && (addr<6)) { + rWrite((ch*6)+(addr&7),val); + } + } +} + +void DivPlatformK007232::acquire(short* bufL, short* bufR, size_t start, size_t len) { + for (size_t h=start; h>4)&0xf)),(k007232.output(1)*((regPool[0x11]>>4)&0xf))}; + bufL[h]=(lout[0]+lout[1])<<4; + bufR[h]=(rout[0]+rout[1])<<4; + for (int i=0; i<2; i++) { + oscBuf[i]->data[oscBuf[i]->needle++]=(lout[i]+rout[i])<<4; + } + } else { + const signed int out[2]={(k007232.output(0)*(regPool[0xc]&0xf)),(k007232.output(1)*((regPool[0xc]>>4)&0xf))}; + bufL[h]=bufR[h]=(out[0]+out[1])<<4; + for (int i=0; i<2; i++) { + oscBuf[i]->data[oscBuf[i]->needle++]=out[i]<<5; + } + } + } +} + +u8 DivPlatformK007232::read_sample(u8 ne, u32 address) { + if ((sampleMem!=NULL) && (addresscalcArp(chan[i].note,chan[i].std.arp.val)); + } + chan[i].freqChanged=true; + } + if (chan[i].std.pitch.had) { + if (chan[i].std.pitch.mode) { + chan[i].pitch2+=chan[i].std.pitch.val; + CLAMP_VAR(chan[i].pitch2,-32768,32767); + } else { + chan[i].pitch2=chan[i].std.pitch.val; + } + chan[i].freqChanged=true; + } + // volume and panning registers are off-chip + if (chan[i].std.panL.had) { + chan[i].panning&=0xf0; + chan[i].panning|=chan[i].std.panL.val&15; + if (!isMuted[i] && stereo) { + chan[i].volumeChanged=true; + } + } + if (chan[i].std.panR.had) { + chan[i].panning&=0x0f; + chan[i].panning|=(chan[i].std.panR.val&15)<<4; + if (!isMuted[i] && stereo) { + chan[i].volumeChanged=true; + } + } + if (chan[i].std.phaseReset.had) { + if (chan[i].std.phaseReset.val==1 && chan[i].active) { + chan[i].audPos=0; + chan[i].setPos=true; + } + } + if (chan[i].volumeChanged) { + if (stereo) { + chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>0)&0xf))/15); + chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>4)&0xf))/15); + rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + } + else { + chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; + rWrite(0xc,regPool[0xc]&~(0xf<<(i<<2))|((chan[i].outVol&0xf)<<(i<<2))); + } + chan[i].volumeChanged=false; + } + if (chan[i].setPos) { + // force keyon + chan[i].keyOn=true; + chan[i].setPos=false; + } else { + chan[i].audPos=0; + } + if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { + double off=1.0; + int sample=chan[i].sample; + if (sample>=0 && samplesong.sampleLen) { + DivSample* s=parent->getSample(sample); + if (s->centerRate<1) { + off=1.0; + } else { + off=8363.0/s->centerRate; + } + } + unsigned char loopon=regPool[0xd]|(1<getSample(chan[i].sample); + chan[i].freq=0x1000-(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)); + if (chan[i].freq>4095) chan[i].freq=4095; + if (chan[i].freq<0) chan[i].freq=0; + if (chan[i].keyOn) { + unsigned int bank=0; + unsigned int start=0; + unsigned int loop=0; + if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { + bank=sampleOffK007232[chan[i].sample]>>17; + start=sampleOffK007232[chan[i].sample]&0x1ffff; + loop=start+s->length8; + } + if (chan[i].audPos>0) { + start=start+MIN(chan[i].audPos,MIN(131072-1,s->length8)); + } + if (s->isLoopable()) { + loop=start+s->loopStart; + rWrite(0xd,loopon); + } else { + rWrite(0xd,loopoff); + } + start=MIN(start,MIN(getSampleMemCapacity(),131072)-1); + loop=MIN(loop,MIN(getSampleMemCapacity(),131072)-1); + // force keyoff first + chWrite(i,0,0); + chWrite(i,1,0); + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,0x1); + chWrite(i,5,0); + // keyon + rWrite(0x12+i,bank); + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chWrite(i,2,start&0xff); + chWrite(i,3,start>>8); + chWrite(i,4,start>>16); + chWrite(i,5,0); + if (s->isLoopable()) { + chWrite(i,2,loop&0xff); + chWrite(i,3,loop>>8); + chWrite(i,4,loop>>16); + } + if (!chan[i].std.vol.had) { + chan[i].outVol=chan[i].vol; + if (!isMuted[i]) { + chan[i].volumeChanged=true; + } + } + chan[i].keyOn=false; + } + if (chan[i].keyOff) { + chWrite(i,0,0); + chWrite(i,1,0); + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,0x1); + chWrite(i,5,0); + chan[i].keyOff=false; + } + if (chan[i].freqChanged) { + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chan[i].freqChanged=false; + } + } + } +} + +int DivPlatformK007232::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: { + DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_AMIGA); + chan[c.chan].macroVolMul=ins->type==DIV_INS_AMIGA?64:15; + chan[c.chan].sample=ins->amiga.getSample(c.value); + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); + } + if (chan[c.chan].sample<0 || chan[c.chan].sample>=parent->song.sampleLen) { + chan[c.chan].sample=-1; + } + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + } + chan[c.chan].active=true; + chan[c.chan].keyOn=true; + chan[c.chan].macroInit(ins); + if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { + chan[c.chan].outVol=chan[c.chan].vol; + if (!isMuted[c.chan]) { + chan[c.chan].volumeChanged=true; + } + } + break; + } + case DIV_CMD_NOTE_OFF: + chan[c.chan].sample=-1; + chan[c.chan].active=false; + chan[c.chan].keyOff=true; + chan[c.chan].macroInit(NULL); + break; + case DIV_CMD_NOTE_OFF_ENV: + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].ins=c.value; + } + break; + case DIV_CMD_VOLUME: + if (chan[c.chan].vol!=c.value) { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + if (!isMuted[c.chan]) { + chan[c.chan].volumeChanged=true; + } + } + } + break; + case DIV_CMD_GET_VOLUME: + if (chan[c.chan].std.vol.has) { + return chan[c.chan].vol; + } + return chan[c.chan].outVol; + break; + case DIV_CMD_PANNING: + chan[c.chan].panning=(c.value>>4)|(c.value2&0xf0); + if (!isMuted[c.chan] && stereo) { + chan[c.chan].volumeChanged=true; + } + break; + case DIV_CMD_PITCH: + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + case DIV_CMD_NOTE_PORTA: { + int destFreq=NOTE_PERIODIC(c.value2); + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + chan[c.chan].baseFreq+=c.value; + if (chan[c.chan].baseFreq>=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } else { + chan[c.chan].baseFreq-=c.value; + if (chan[c.chan].baseFreq<=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((chan[c.chan].std.arp.will && !chan[c.chan].std.arp.mode)?(chan[c.chan].std.arp.val-12):(0))); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + break; + } + case DIV_CMD_PRE_PORTA: + if (chan[c.chan].active && c.value2) { + if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_AMIGA)); + } + if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note); + chan[c.chan].inPorta=c.value; + break; + case DIV_CMD_SAMPLE_POS: + chan[c.chan].audPos=c.value; + chan[c.chan].setPos=true; + break; + case DIV_CMD_GET_VOLMAX: + return 255; + break; + case DIV_ALWAYS_SET_VOLUME: + return 1; + break; + default: + break; + } + return 1; +} + +void DivPlatformK007232::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; + chan[ch].volumeChanged=true; +} + +void DivPlatformK007232::forceIns() { + for (int i=0; i<2; i++) { + chan[i].insChanged=true; + chan[i].freqChanged=true; + chan[i].sample=-1; + } +} + +void* DivPlatformK007232::getChanState(int ch) { + return &chan[ch]; +} + +DivMacroInt* DivPlatformK007232::getChanMacroInt(int ch) { + return &chan[ch].std; +} + +DivDispatchOscBuffer* DivPlatformK007232::getOscBuffer(int ch) { + return oscBuf[ch]; +} + +void DivPlatformK007232::reset() { + memset(regPool,0,32); + k007232.reset(); + for (int i=0; i<2; i++) { + chan[i]=DivPlatformK007232::Channel(); + chan[i].std.setEngine(parent); + // keyoff all channels + chWrite(i,0,0); + chWrite(i,1,0); + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,1); + chWrite(i,5,0); + } +} + +bool DivPlatformK007232::isStereo() { + return stereo; +} + +void DivPlatformK007232::notifyInsChange(int ins) { + for (int i=0; i<2; i++) { + if (chan[i].ins==ins) { + chan[i].insChanged=true; + } + } +} + +void DivPlatformK007232::notifyWaveChange(int wave) { + // TODO when wavetables are added + // TODO they probably won't be added unless the samples reside in RAM +} + +void DivPlatformK007232::notifyInsDeletion(void* ins) { + for (int i=0; i<2; i++) { + chan[i].std.notifyInsDeletion((DivInstrument*)ins); + } +} + +void DivPlatformK007232::setFlags(const DivConfig& flags) { + chipClock=COLOR_NTSC; + CHECK_CUSTOM_CLOCK; + rate=chipClock/4; + stereo=flags.getBool("stereo",false); + for (int i=0; i<2; i++) { + oscBuf[i]->rate=rate; + } +} + +void DivPlatformK007232::poke(unsigned int addr, unsigned short val) { + rWrite(addr&0x1f,val); +} + +void DivPlatformK007232::poke(std::vector& wlist) { + for (DivRegWrite& i: wlist) rWrite(i.addr&0x1f,i.val); +} + +unsigned char* DivPlatformK007232::getRegisterPool() { + return regPool; +} + +int DivPlatformK007232::getRegisterPoolSize() { + return 32; +} + +const void* DivPlatformK007232::getSampleMem(int index) { + return index == 0 ? sampleMem : NULL; +} + +size_t DivPlatformK007232::getSampleMemCapacity(int index) { + return index == 0 ? 16777216 : 0; +} + +size_t DivPlatformK007232::getSampleMemUsage(int index) { + return index == 0 ? sampleMemLen : 0; +} + +bool DivPlatformK007232::isSampleLoaded(int index, int sample) { + if (index!=0) return false; + if (sample<0 || sample>255) return false; + return sampleLoaded[sample]; +} + +void DivPlatformK007232::renderSamples(int sysID) { + memset(sampleMem,0xc0,getSampleMemCapacity()); + memset(sampleOffK007232,0,256*sizeof(unsigned int)); + memset(sampleLoaded,0,256*sizeof(bool)); + + size_t memPos=0; + for (int i=0; isong.sampleLen; i++) { + DivSample* s=parent->song.sample[i]; + if (!s->renderOn[0][sysID]) { + sampleOffK007232[i]=0; + continue; + } + + int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); + int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-1,length); + if (actualLength>0) { + if (actualLength>131072-1) { + actualLength=131072-1; + } + if ((memPos&0xfe0000)!=((memPos+actualLength+1)&0xfe0000)) { + memPos=(memPos+0x1ffff)&0xfe0000; + } + sampleOffK007232[i]=memPos; + for (int j=0; jdata8[j])^0x80; + sampleMem[memPos++]=(val>>1)&0x7f; + } + // write end of sample marker + memset(&sampleMem[memPos],0xc0,1); + memPos+=1; + } + if (actualLength +#include "../macroInt.h" +#include "vgsound_emu/src/k007232/k007232.hpp" + +class DivPlatformK007232: public DivDispatch, public k007232_intf { + struct Channel { + int freq, baseFreq, pitch, pitch2; + unsigned int audPos; + int sample, wave, ins; + int note; + int panning; + bool active, insChanged, volumeChanged, freqChanged, keyOn, keyOff, inPorta, setPos; + int vol, outVol, lvol, rvol; + int macroVolMul; + DivMacroInt std; + void macroInit(DivInstrument* which) { + std.init(which); + pitch2=0; + } + Channel(): + freq(0), + baseFreq(0), + pitch(0), + pitch2(0), + audPos(0), + sample(-1), + ins(-1), + note(0), + panning(255), + active(false), + insChanged(true), + volumeChanged(false), + freqChanged(false), + keyOn(false), + keyOff(false), + inPorta(false), + setPos(false), + vol(15), + outVol(15), + lvol(15), + rvol(15), + macroVolMul(64) {} + }; + Channel chan[2]; + DivDispatchOscBuffer* oscBuf[2]; + bool isMuted[2]; + struct QueuedWrite { + unsigned short addr; + unsigned char val; + unsigned short delay; + QueuedWrite(unsigned short a, unsigned char v, unsigned short d=1): + addr(a), + val(v), + delay(d) {} + }; + std::queue writes; + unsigned int sampleOffK007232[256]; + bool sampleLoaded[256]; + + int delay; + bool stereo; + + unsigned char* sampleMem; + size_t sampleMemLen; + k007232_core k007232; + unsigned char regPool[32]; + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); + + public: + u8 read_sample(u8 ne, u32 address); + void acquire(short* bufL, short* bufR, size_t start, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + DivMacroInt* getChanMacroInt(int ch); + DivDispatchOscBuffer* getOscBuffer(int chan); + unsigned char* getRegisterPool(); + int getRegisterPoolSize(); + void reset(); + void forceIns(); + void tick(bool sysTick=true); + void muteChannel(int ch, bool mute); + bool isStereo(); + void setChipModel(int type); + void notifyInsChange(int ins); + void notifyWaveChange(int wave); + void notifyInsDeletion(void* ins); + void setFlags(const DivConfig& flags); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + const char** getRegisterSheet(); + const void* getSampleMem(int index = 0); + size_t getSampleMemCapacity(int index = 0); + size_t getSampleMemUsage(int index = 0); + bool isSampleLoaded(int index, int sample); + void renderSamples(int chipID); + int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); + void quit(); + DivPlatformK007232(): + DivDispatch(), + k007232_intf(), + k007232(*this) {} + private: + void chWrite(unsigned char ch, unsigned int addr, unsigned char val); +}; + +#endif diff --git a/src/engine/song.h b/src/engine/song.h index 589a1ea5f..d63ab0ed9 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -116,6 +116,7 @@ enum DivSystem { DIV_SYSTEM_YM2612_FRAC_EXT, DIV_SYSTEM_MSM5232, DIV_SYSTEM_T6W28, + DIV_SYSTEM_K007232, DIV_SYSTEM_PCM_DAC, DIV_SYSTEM_PONG, DIV_SYSTEM_DUMMY diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 9cd0b33ff..0c7d8bf46 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1693,6 +1693,16 @@ void DivEngine::registerSystems() { {DIV_INS_AMIGA} ); + sysDefs[DIV_SYSTEM_K007232]=new DivSysDef( + "Konami K007232", NULL, 0xc1/*Placeholder*/, 0, 2, false, true, 0, false, 1U<type==DIV_INS_VRC6 || ins->type==DIV_INS_SU || ins->type==DIV_INS_SNES || - ins->type==DIV_INS_ES5506) { + ins->type==DIV_INS_ES5506 || + ins->type==DIV_INS_K007232) { if (ImGui::BeginTabItem((ins->type==DIV_INS_SU)?"Sound Unit":"Sample")) { String sName; if (ins->amiga.initSample<0 || ins->amiga.initSample>=e->song.sampleLen) { @@ -4987,7 +4988,7 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_TIA || ins->type==DIV_INS_AMIGA || ins->type==DIV_INS_SCC || ins->type==DIV_INS_PET || ins->type==DIV_INS_VIC || ins->type==DIV_INS_SEGAPCM || - ins->type==DIV_INS_FM) { + ins->type==DIV_INS_FM || ins->type==DIV_INS_K007232) { dutyMax=0; } if (ins->type==DIV_INS_VBOY) { @@ -5070,6 +5071,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_MSM6258) waveMax=0; if (ins->type==DIV_INS_MSM6295) waveMax=0; if (ins->type==DIV_INS_SEGAPCM) waveMax=0; + if (ins->type==DIV_INS_K007232) waveMax=0; if (ins->type==DIV_INS_SU) waveMax=7; if (ins->type==DIV_INS_PET) { waveMax=8; @@ -5159,7 +5161,7 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_X1_010 || ins->type==DIV_INS_PCE || ins->type==DIV_INS_MIKEY || ins->type==DIV_INS_SAA1099 || ins->type==DIV_INS_NAMCO || ins->type==DIV_INS_RF5C68 || - ins->type==DIV_INS_VBOY || ins->type==DIV_INS_T6W28) { + ins->type==DIV_INS_VBOY || ins->type==DIV_INS_T6W28 || ins->type==DIV_INS_K007232) { panMax=15; } if (ins->type==DIV_INS_SEGAPCM) { @@ -5268,7 +5270,8 @@ void FurnaceGUI::drawInsEdit() { ins->type==DIV_INS_ES5506 || ins->type==DIV_INS_T6W28 || ins->type==DIV_INS_VBOY || - (ins->type==DIV_INS_X1_010 && ins->amiga.useSample)) { + (ins->type==DIV_INS_X1_010 && ins->amiga.useSample) || + ins->type==DIV_INS_K007232) { macroList.push_back(FurnaceGUIMacroDesc("Phase Reset",&ins->std.phaseResetMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); } if (ex1Max>0) { diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 6072570ee..84e18b3cf 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -1143,6 +1143,11 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_SNES, 64, 0, "") } ); + ENTRY( + "Konami K007232", { + CH(DIV_SYSTEM_K007232, 64, 0, "") + } + ); ENTRY( "Generic PCM DAC", { CH(DIV_SYSTEM_PCM_DAC, 64, 0, "") diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 1c8cebb5b..dc143e390 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1787,6 +1787,7 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_INSTR_QSOUND,"QSound"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_YMZ280B,"YMZ280B"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_RF5C68,"RF5C68"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_K007232,"K007232"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_UNKNOWN,"Other/Unknown"); ImGui::TreePop(); } diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 170e2d8bd..ebfca37db 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -1546,6 +1546,20 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo } break; } + case DIV_SYSTEM_K007232: { + bool stereo=flags.getBool("stereo",false); + + if (ImGui::Checkbox("Stereo",&stereo)) { + altered=true; + } + + if (altered) { + e->lockSave([&]() { + flags.set("stereo",stereo); + }); + } + break; + } case DIV_SYSTEM_SWAN: case DIV_SYSTEM_BUBSYS_WSG: case DIV_SYSTEM_PET: From 2f6789fca72fcf46f6e33d4160137654ea77a176 Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 8 Dec 2022 14:56:21 +0900 Subject: [PATCH 02/36] Add presets with K007232 --- src/gui/presets.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 84e18b3cf..b1139a22d 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -1331,6 +1331,12 @@ void FurnaceGUI::initSystemPresets() { // VLM5030 exists but not used for music at all } ); + ENTRY( + "Konami MX5000", { + CH(DIV_SYSTEM_YM2151, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); ENTRY( "Konami Battlantis", { CH(DIV_SYSTEM_OPL2, 64, 0, "clockSel=3"), // 3MHz @@ -1355,6 +1361,54 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, "clockSel=3") // "" } ); + ENTRY( + "Konami Fast Lane", { + CH(DIV_SYSTEM_K007232, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Chequered Flag", { + CH(DIV_SYSTEM_YM2151, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Haunted Castle", { + CH(DIV_SYSTEM_OPL2, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_SCC, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Haunted Castle (drums mode)", { + CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_SCC, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Hot Chase", { + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true") // "" + } + ); + ENTRY( + "Konami S.P.Y.", { + CH(DIV_SYSTEM_OPL2, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami S.P.Y. (drums mode)", { + CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); ENTRY( "Konami Hexion", { CH(DIV_SYSTEM_SCC, 64, 0, "clockSel=2"), // 1.5MHz (3MHz input) From 186eb23dd0ff8ec62f459fea39160e68ae8f9b3f Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 8 Dec 2022 15:12:26 +0900 Subject: [PATCH 03/36] Fix build --- src/engine/platform/k007232.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 6dee42356..4b8f8ad11 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -152,7 +152,7 @@ void DivPlatformK007232::tick(bool sysTick) { } else { chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; - rWrite(0xc,regPool[0xc]&~(0xf<<(i<<2))|((chan[i].outVol&0xf)<<(i<<2))); + rWrite(0xc,(regPool[0xc]&~(0xf<<(i<<2)))|((chan[i].outVol&0xf)<<(i<<2))); } chan[i].volumeChanged=false; } From 80b1285ac9eb3703799b45f824ec49de1e490535 Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 8 Dec 2022 19:20:01 +0900 Subject: [PATCH 04/36] Fix channel count --- src/engine/platform/k007232.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 4b8f8ad11..8fc86fd63 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -530,7 +530,7 @@ int DivPlatformK007232::init(DivEngine* p, int channels, int sugRate, const DivC setFlags(flags); reset(); - return 8; + return 2; } void DivPlatformK007232::quit() { From 142f746da1b904dfc33d6b538810a18a416493be Mon Sep 17 00:00:00 2001 From: cam900 Date: Thu, 8 Dec 2022 19:22:22 +0900 Subject: [PATCH 05/36] Add docs --- papers/doc/7-systems/k007232.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/papers/doc/7-systems/k007232.md b/papers/doc/7-systems/k007232.md index 92b4759c4..1e5dc7684 100644 --- a/papers/doc/7-systems/k007232.md +++ b/papers/doc/7-systems/k007232.md @@ -4,6 +4,8 @@ a Konami's 2 channel PCM sound chip was used in their arcade boards in 1986-1990 Its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). +It has 7 bit digital output per each channel and no volume register on chip, so it needs external logic to control channel volume. + # effects - Nothing for now From 4cb9cf793921cfc99d1539a37b75518e35dd0208 Mon Sep 17 00:00:00 2001 From: cam900 Date: Fri, 9 Dec 2022 11:02:40 +0900 Subject: [PATCH 06/36] Minor formatting --- src/engine/sysDef.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 0c7d8bf46..8dff95b23 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1694,7 +1694,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_K007232]=new DivSysDef( - "Konami K007232", NULL, 0xc1/*Placeholder*/, 0, 2, false, true, 0, false, 1U< Date: Sat, 10 Dec 2022 13:06:58 +0900 Subject: [PATCH 07/36] Remove condition duplication --- src/engine/platform/k007232.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 8fc86fd63..2652202ee 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -103,9 +103,7 @@ void DivPlatformK007232::tick(bool sysTick) { signed char macroVol=((chan[i].vol&0xf)*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/chan[i].macroVolMul; if ((!isMuted[i]) && (macroVol!=chan[i].outVol)) { chan[i].outVol=macroVol; - if (!isMuted[i]) { - chan[i].volumeChanged=true; - } + chan[i].volumeChanged=true; } } if (chan[i].std.arp.had) { From 0897029a164c8308993125fd408d7837bd58b649 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:12:03 +0900 Subject: [PATCH 08/36] Minor desync fixes --- src/engine/platform/k007232.cpp | 23 +++++++++++++++-------- src/engine/platform/k007232.h | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 2652202ee..16034a8ba 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -150,7 +150,8 @@ void DivPlatformK007232::tick(bool sysTick) { } else { chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; - rWrite(0xc,(regPool[0xc]&~(0xf<<(i<<2)))|((chan[i].outVol&0xf)<<(i<<2))); + lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].outVol&0xf)<<(i<<2)); + rWrite(0xc,lastVolume); } chan[i].volumeChanged=false; } @@ -172,7 +173,7 @@ void DivPlatformK007232::tick(bool sysTick) { off=8363.0/s->centerRate; } } - unsigned char loopon=regPool[0xd]|(1<getSample(chan[i].sample); chan[i].freq=0x1000-(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)); @@ -190,12 +191,6 @@ void DivPlatformK007232::tick(bool sysTick) { if (chan[i].audPos>0) { start=start+MIN(chan[i].audPos,MIN(131072-1,s->length8)); } - if (s->isLoopable()) { - loop=start+s->loopStart; - rWrite(0xd,loopon); - } else { - rWrite(0xd,loopoff); - } start=MIN(start,MIN(getSampleMemCapacity(),131072)-1); loop=MIN(loop,MIN(getSampleMemCapacity(),131072)-1); // force keyoff first @@ -206,6 +201,13 @@ void DivPlatformK007232::tick(bool sysTick) { chWrite(i,4,0x1); chWrite(i,5,0); // keyon + if (s->isLoopable()) { + loop=start+s->loopStart; + lastLoop=loopon; + } else { + lastLoop=loopoff; + } + rWrite(0xd,lastLoop); rWrite(0x12+i,bank); chWrite(i,0,chan[i].freq&0xff); chWrite(i,1,(chan[i].freq>>8)&0xf); @@ -391,8 +393,13 @@ DivDispatchOscBuffer* DivPlatformK007232::getOscBuffer(int ch) { } void DivPlatformK007232::reset() { + while (!writes.empty()) { + writes.pop(); + } memset(regPool,0,32); k007232.reset(); + lastLoop=0; + lastVolume=0xff; for (int i=0; i<2; i++) { chan[i]=DivPlatformK007232::Channel(); chan[i].std.setEngine(parent); diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 5cadc0df6..46e68a159 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -80,7 +80,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { unsigned int sampleOffK007232[256]; bool sampleLoaded[256]; - int delay; + int delay, lastLoop, lastVolume; bool stereo; unsigned char* sampleMem; From be2b67210d1503ec0339cb09580aeff9c771a0b8 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:22:14 +0900 Subject: [PATCH 09/36] Reduce line width, Add debug view for K007232 --- src/engine/platform/k007232.cpp | 8 ++++--- src/gui/debug.cpp | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 16034a8ba..5e84a0711 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -72,15 +72,17 @@ void DivPlatformK007232::acquire(short* bufL, short* bufR, size_t start, size_t k007232.tick(); if (stereo) { - const signed int lout[2]={(k007232.output(0)*(regPool[0x10]&0xf)),(k007232.output(1)*(regPool[0x11]&0xf))}; - const signed int rout[2]={(k007232.output(0)*((regPool[0x10]>>4)&0xf)),(k007232.output(1)*((regPool[0x11]>>4)&0xf))}; + const unsigned char vol1=regPool[0x10],vol2=regPool[0x11]; + const signed int lout[2]={(k007232.output(0)*(vol1&0xf)),(k007232.output(1)*(vol2&0xf))}; + const signed int rout[2]={(k007232.output(0)*((vol1>>4)&0xf)),(k007232.output(1)*((vol2>>4)&0xf))}; bufL[h]=(lout[0]+lout[1])<<4; bufR[h]=(rout[0]+rout[1])<<4; for (int i=0; i<2; i++) { oscBuf[i]->data[oscBuf[i]->needle++]=(lout[i]+rout[i])<<4; } } else { - const signed int out[2]={(k007232.output(0)*(regPool[0xc]&0xf)),(k007232.output(1)*((regPool[0xc]>>4)&0xf))}; + const unsigned char vol=regPool[0xc]; + const signed int out[2]={(k007232.output(0)*(vol&0xf)),(k007232.output(1)*((vol>>4)&0xf))}; bufL[h]=bufR[h]=(out[0]+out[1])<<4; for (int i=0; i<2; i++) { oscBuf[i]->data[oscBuf[i]->needle++]=out[i]<<5; diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index ddd504049..fb03363a9 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -47,6 +47,7 @@ #include "../engine/platform/vrc6.h" #include "../engine/platform/lynx.h" #include "../engine/platform/pcmdac.h" +#include "../engine/platform/k007232.h" #include "../engine/platform/dummy.h" #define COMMON_CHIP_DEBUG \ @@ -553,6 +554,17 @@ void putDispatchChip(void* data, int type) { ImGui::TextColored(ch->outStereo?colorOn:colorOff,">> OutStereo"); break; } + case DIV_SYSTEM_K007232: { + DivPlatformK007232* ch=(DivPlatformK007232*)data; + ImGui::Text("> K007232"); + COMMON_CHIP_DEBUG; + ImGui::Text("- delay: %.2x",ch->delay); + ImGui::Text("- lastLoop: %.2x",ch->lastLoop); + ImGui::Text("- lastVolume: %.2x",ch->lastVolume); + COMMON_CHIP_DEBUG_BOOL; + ImGui::TextColored(ch->stereo?colorOn:colorOff,">> Stereo"); + break; + } default: ImGui::Text("Unimplemented chip! Help!"); break; @@ -1114,6 +1126,34 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); break; } + case DIV_SYSTEM_K007232: { + DivPlatformK007232::Channel* ch=(DivPlatformK007232::Channel*)data; + ImGui::Text("> K007232"); + ImGui::Text("* freq:"); + ImGui::Text(" - base: %d",ch->baseFreq); + ImGui::Text(" - pitch: %d",ch->pitch); + ImGui::Text(" - pitch2: %d",ch->pitch2); + ImGui::Text("* note: %d",ch->note); + ImGui::Text("* Sample: %d",ch->sample); + ImGui::Text(" - pos: %d",ch->audPos); + ImGui::Text("- wave: %d",ch->wave); + ImGui::Text("- ins: %d",ch->ins); + ImGui::Text("- panning: %d",ch->panning); + ImGui::Text("- vol: %.2x",ch->vol); + ImGui::Text("- outVol: %.2x",ch->outVol); + ImGui::Text("- lvol: %.2x",ch->lvol); + ImGui::Text("- rvol: %.2x",ch->rvol); + ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); + ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); + ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); + ImGui::TextColored(ch->volumeChanged?colorOn:colorOff,">> VolumeChanged"); + ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); + ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); + ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); + ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); + break; + } default: ImGui::Text("Unimplemented chip! Help!"); break; From 507f91f26188827f76bd457335a14085556e9267 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:25:32 +0900 Subject: [PATCH 10/36] Fix delay issue, Add debug view for frequency --- src/engine/platform/k007232.cpp | 1 + src/gui/debug.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 5e84a0711..916a942bb 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -57,6 +57,7 @@ inline void DivPlatformK007232::chWrite(unsigned char ch, unsigned int addr, uns void DivPlatformK007232::acquire(short* bufL, short* bufR, size_t start, size_t len) { for (size_t h=start; h K007232"); - ImGui::Text("* freq:"); + ImGui::Text("* freq: %d",ch->freq); ImGui::Text(" - base: %d",ch->baseFreq); ImGui::Text(" - pitch: %d",ch->pitch); ImGui::Text(" - pitch2: %d",ch->pitch2); From 853ca714d011b001cec34d6acea2ca7cb28213a4 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:32:56 +0900 Subject: [PATCH 11/36] Fix click --- src/engine/platform/k007232.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 916a942bb..8546a851a 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -176,8 +176,6 @@ void DivPlatformK007232::tick(bool sysTick) { off=8363.0/s->centerRate; } } - unsigned char loopon=lastLoop|(1<getSample(chan[i].sample); chan[i].freq=0x1000-(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)); if (chan[i].freq>4095) chan[i].freq=4095; @@ -206,9 +204,9 @@ void DivPlatformK007232::tick(bool sysTick) { // keyon if (s->isLoopable()) { loop=start+s->loopStart; - lastLoop=loopon; + lastLoop|=(1< Date: Sat, 10 Dec 2022 13:34:48 +0900 Subject: [PATCH 12/36] Minor fix --- src/engine/platform/k007232.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 8546a851a..1b8be3948 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -206,7 +206,7 @@ void DivPlatformK007232::tick(bool sysTick) { loop=start+s->loopStart; lastLoop|=(1< Date: Sat, 10 Dec 2022 13:44:24 +0900 Subject: [PATCH 13/36] Reduce register spamming --- src/engine/platform/k007232.cpp | 23 +++++++++++++++++------ src/engine/platform/k007232.h | 5 +++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 1b8be3948..3c2ad1578 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -149,12 +149,19 @@ void DivPlatformK007232::tick(bool sysTick) { if (stereo) { chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>0)&0xf))/15); chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>4)&0xf))/15); - rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + const unsigned char prevPan=lastPan[i]; + lastPan[i]=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); + if (prevPan!=lastPan[i]) { + rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + } } else { chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; + const unsigned char prevVolume=lastVolume; lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].outVol&0xf)<<(i<<2)); - rWrite(0xc,lastVolume); + if (prevVolume!=lastVolume) { + rWrite(0xc,lastVolume); + } } chan[i].volumeChanged=false; } @@ -202,13 +209,16 @@ void DivPlatformK007232::tick(bool sysTick) { chWrite(i,4,0x1); chWrite(i,5,0); // keyon + const unsigned char prevLoop=lastLoop; if (s->isLoopable()) { loop=start+s->loopStart; lastLoop|=(1<>8)&0xf); @@ -399,10 +409,11 @@ void DivPlatformK007232::reset() { while (!writes.empty()) { writes.pop(); } - memset(regPool,0,32); + memset(regPool,0,20); k007232.reset(); lastLoop=0; - lastVolume=0xff; + lastVolume=0; + lastPan[0]=lastPan[1]=0; for (int i=0; i<2; i++) { chan[i]=DivPlatformK007232::Channel(); chan[i].std.setEngine(parent); @@ -462,7 +473,7 @@ unsigned char* DivPlatformK007232::getRegisterPool() { } int DivPlatformK007232::getRegisterPoolSize() { - return 32; + return 20; } const void* DivPlatformK007232::getSampleMem(int index) { diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 46e68a159..2eb788379 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -80,13 +80,14 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { unsigned int sampleOffK007232[256]; bool sampleLoaded[256]; - int delay, lastLoop, lastVolume; + int delay; + unsigned char lastLoop, lastVolume, lastPan[2]; bool stereo; unsigned char* sampleMem; size_t sampleMemLen; k007232_core k007232; - unsigned char regPool[32]; + unsigned char regPool[20]; friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); From bf16f8f59eef80df61597cc6d1bda3ff88b8c4e5 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 13:57:39 +0900 Subject: [PATCH 14/36] Reduce register spamming(again) --- src/engine/platform/k007232.cpp | 37 ++++++++++++++++++++------------- src/engine/platform/k007232.h | 10 ++++++--- src/gui/debug.cpp | 5 ++++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 3c2ad1578..f18577ee0 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -149,10 +149,10 @@ void DivPlatformK007232::tick(bool sysTick) { if (stereo) { chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>0)&0xf))/15); chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>4)&0xf))/15); - const unsigned char prevPan=lastPan[i]; - lastPan[i]=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); - if (prevPan!=lastPan[i]) { + const int newPan=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); + if (chan[i].prevPan!=newPan) { rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + chan[i].prevPan=newPan; } } else { @@ -202,8 +202,6 @@ void DivPlatformK007232::tick(bool sysTick) { start=MIN(start,MIN(getSampleMemCapacity(),131072)-1); loop=MIN(loop,MIN(getSampleMemCapacity(),131072)-1); // force keyoff first - chWrite(i,0,0); - chWrite(i,1,0); chWrite(i,2,0xff); chWrite(i,3,0xff); chWrite(i,4,0x1); @@ -219,14 +217,20 @@ void DivPlatformK007232::tick(bool sysTick) { if (prevLoop!=lastLoop) { rWrite(0xd,lastLoop); } - rWrite(0x12+i,bank); - chWrite(i,0,chan[i].freq&0xff); - chWrite(i,1,(chan[i].freq>>8)&0xf); + if (chan[i].prevBank!=bank) { + rWrite(0x12+i,bank); + chan[i].prevBank=bank; + } + if (chan[i].prevFreq!=chan[i].freq) { + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } chWrite(i,2,start&0xff); chWrite(i,3,start>>8); chWrite(i,4,start>>16); chWrite(i,5,0); - if (s->isLoopable()) { + if (s->isLoopable() && start!=loop) { chWrite(i,2,loop&0xff); chWrite(i,3,loop>>8); chWrite(i,4,loop>>16); @@ -240,19 +244,23 @@ void DivPlatformK007232::tick(bool sysTick) { chan[i].keyOn=false; } if (chan[i].keyOff) { - chWrite(i,0,0); - chWrite(i,1,0); chWrite(i,2,0xff); chWrite(i,3,0xff); chWrite(i,4,0x1); chWrite(i,5,0); + const unsigned char prevLoop=lastLoop; lastLoop&=~(1<>8)&0xf); + if (chan[i].prevFreq!=chan[i].freq) { + chWrite(i,0,chan[i].freq&0xff); + chWrite(i,1,(chan[i].freq>>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } chan[i].freqChanged=false; } } @@ -413,7 +421,6 @@ void DivPlatformK007232::reset() { k007232.reset(); lastLoop=0; lastVolume=0; - lastPan[0]=lastPan[1]=0; for (int i=0; i<2; i++) { chan[i]=DivPlatformK007232::Channel(); chan[i].std.setEngine(parent); diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 2eb788379..8b42b5102 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -27,11 +27,12 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { struct Channel { - int freq, baseFreq, pitch, pitch2; + int freq, prevFreq, baseFreq, pitch, pitch2; unsigned int audPos; + int prevBank; int sample, wave, ins; int note; - int panning; + int panning, prevPan; bool active, insChanged, volumeChanged, freqChanged, keyOn, keyOff, inPorta, setPos; int vol, outVol, lvol, rvol; int macroVolMul; @@ -42,14 +43,17 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { } Channel(): freq(0), + prevFreq(-1), baseFreq(0), pitch(0), pitch2(0), audPos(0), + prevBank(-1), sample(-1), ins(-1), note(0), panning(255), + prevPan(-1), active(false), insChanged(true), volumeChanged(false), @@ -81,7 +85,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { bool sampleLoaded[256]; int delay; - unsigned char lastLoop, lastVolume, lastPan[2]; + unsigned char lastLoop, lastVolume; bool stereo; unsigned char* sampleMem; diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index 91e5bbbc6..d62fcd5d2 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -1130,15 +1130,18 @@ void putDispatchChan(void* data, int chanNum, int type) { DivPlatformK007232::Channel* ch=(DivPlatformK007232::Channel*)data; ImGui::Text("> K007232"); ImGui::Text("* freq: %d",ch->freq); + ImGui::Text(" - prev: %d",ch->prevFreq); ImGui::Text(" - base: %d",ch->baseFreq); ImGui::Text(" - pitch: %d",ch->pitch); ImGui::Text(" - pitch2: %d",ch->pitch2); ImGui::Text("* note: %d",ch->note); ImGui::Text("* Sample: %d",ch->sample); ImGui::Text(" - pos: %d",ch->audPos); + ImGui::Text(" - prevBank: %d",ch->prevBank); ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- ins: %d",ch->ins); - ImGui::Text("- panning: %d",ch->panning); + ImGui::Text("* panning: %d",ch->panning); + ImGui::Text(" - prev: %d",ch->prevPan); ImGui::Text("- vol: %.2x",ch->vol); ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- lvol: %.2x",ch->lvol); From 793faed447a260c3568d47b302233eaaa3aeec64 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 14:26:26 +0900 Subject: [PATCH 15/36] constant-ize --- src/engine/platform/k007232.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index f18577ee0..6f367a509 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -103,7 +103,7 @@ void DivPlatformK007232::tick(bool sysTick) { for (int i=0; i<2; i++) { chan[i].std.next(); if (chan[i].std.vol.had) { - signed char macroVol=((chan[i].vol&0xf)*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/chan[i].macroVolMul; + const signed char macroVol=((chan[i].vol&0xf)*MIN(chan[i].macroVolMul,chan[i].std.vol.val))/chan[i].macroVolMul; if ((!isMuted[i]) && (macroVol!=chan[i].outVol)) { chan[i].outVol=macroVol; chan[i].volumeChanged=true; @@ -337,7 +337,7 @@ int DivPlatformK007232::dispatch(DivCommand c) { chan[c.chan].freqChanged=true; break; case DIV_CMD_NOTE_PORTA: { - int destFreq=NOTE_PERIODIC(c.value2); + const int destFreq=NOTE_PERIODIC(c.value2); bool return2=false; if (destFreq>chan[c.chan].baseFreq) { chan[c.chan].baseFreq+=c.value; @@ -514,7 +514,7 @@ void DivPlatformK007232::renderSamples(int sysID) { continue; } - int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); + const int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-1,length); if (actualLength>0) { if (actualLength>131072-1) { From 3f2b2a6a4cdbf198d195c3dea314cf2c14142312 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sat, 10 Dec 2022 14:27:15 +0900 Subject: [PATCH 16/36] Fix build --- src/engine/platform/k007232.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 6f367a509..6268ab0a0 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -217,7 +217,7 @@ void DivPlatformK007232::tick(bool sysTick) { if (prevLoop!=lastLoop) { rWrite(0xd,lastLoop); } - if (chan[i].prevBank!=bank) { + if (chan[i].prevBank!=(int)bank) { rWrite(0x12+i,bank); chan[i].prevBank=bank; } From ed779f443a9d6a02ee756e205562b52816401d91 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sun, 11 Dec 2022 16:37:20 +0900 Subject: [PATCH 17/36] Addressing comments --- papers/doc/7-systems/k007232.md | 2 +- papers/format.md | 4 ---- src/engine/fileOps.cpp | 3 --- src/engine/platform/k007232.cpp | 6 +++--- src/engine/platform/k007232.h | 3 +-- src/engine/sysDef.cpp | 2 +- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/papers/doc/7-systems/k007232.md b/papers/doc/7-systems/k007232.md index 1e5dc7684..adf7d95fb 100644 --- a/papers/doc/7-systems/k007232.md +++ b/papers/doc/7-systems/k007232.md @@ -1,6 +1,6 @@ # Konami K007232 -a Konami's 2 channel PCM sound chip was used in their arcade boards in 1986-1990. +a 2-channel PCM sound chip from Konami which was used in some of their 1986-1990 arcade boards. Its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). diff --git a/papers/format.md b/papers/format.md index 25304378e..685e1aefd 100644 --- a/papers/format.md +++ b/papers/format.md @@ -1630,10 +1630,6 @@ chips which aren't on this list don't have any flags. - bit 16-19: outDepth (int) - bit 20: stereo (bool) -## (Placeholder): Konami K007232 - -- bit 0: stereo (bool) - ## 0xe0: QSound - bit 0-11: echoDelay (int) diff --git a/src/engine/fileOps.cpp b/src/engine/fileOps.cpp index 328a28ede..b39aa3445 100644 --- a/src/engine/fileOps.cpp +++ b/src/engine/fileOps.cpp @@ -1571,9 +1571,6 @@ void DivEngine::convertOldFlags(unsigned int oldFlags, DivConfig& newFlags, DivS newFlags.set("echoDelay",(int)(oldFlags&0xfff)); newFlags.set("echoFeedback",(int)((oldFlags>>12)&255)); break; - case DIV_SYSTEM_K007232: - if (oldFlags&1) newFlags.set("stereo",true); - break; default: break; } diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 6268ab0a0..7097f1866 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -128,14 +128,14 @@ void DivPlatformK007232::tick(bool sysTick) { if (chan[i].std.panL.had) { chan[i].panning&=0xf0; chan[i].panning|=chan[i].std.panL.val&15; - if (!isMuted[i] && stereo) { + if ((!isMuted[i]) && stereo) { chan[i].volumeChanged=true; } } if (chan[i].std.panR.had) { chan[i].panning&=0x0f; chan[i].panning|=(chan[i].std.panR.val&15)<<4; - if (!isMuted[i] && stereo) { + if ((!isMuted[i]) && stereo) { chan[i].volumeChanged=true; } } @@ -158,7 +158,7 @@ void DivPlatformK007232::tick(bool sysTick) { else { chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; const unsigned char prevVolume=lastVolume; - lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].outVol&0xf)<<(i<<2)); + lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].lvol&0xf)<<(i<<2)); if (prevVolume!=lastVolume) { rWrite(0xc,lastVolume); } diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 8b42b5102..4bd6d4f76 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -95,6 +95,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); + void chWrite(unsigned char ch, unsigned int addr, unsigned char val); public: u8 read_sample(u8 ne, u32 address); void acquire(short* bufL, short* bufR, size_t start, size_t len); @@ -128,8 +129,6 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { DivDispatch(), k007232_intf(), k007232(*this) {} - private: - void chWrite(unsigned char ch, unsigned int addr, unsigned char val); }; #endif diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 8dff95b23..674344da3 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1694,7 +1694,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_K007232]=new DivSysDef( - "Konami K007232", NULL, 0xc1 /*Placeholder*/, 0, 2, false, true, 0, false, 1U< Date: Sun, 11 Dec 2022 16:49:54 +0900 Subject: [PATCH 18/36] Reduce duplication --- src/engine/platform/k007232.cpp | 8 ++++---- src/engine/platform/k007232.h | 3 ++- src/gui/debug.cpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index 7097f1866..b4501df73 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -146,9 +146,10 @@ void DivPlatformK007232::tick(bool sysTick) { } } if (chan[i].volumeChanged) { + chan[i].resVol=isMuted[i]?0:chan[i].outVol&0xf; if (stereo) { - chan[i].lvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>0)&0xf))/15); - chan[i].rvol=isMuted[i]?0:(((chan[i].outVol&0xf)*((chan[i].panning>>4)&0xf))/15); + chan[i].lvol=((chan[i].resVol&0xf)*((chan[i].panning>>0)&0xf))/15; + chan[i].rvol=((chan[i].resVol&0xf)*((chan[i].panning>>4)&0xf))/15; const int newPan=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); if (chan[i].prevPan!=newPan) { rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); @@ -156,9 +157,8 @@ void DivPlatformK007232::tick(bool sysTick) { } } else { - chan[i].lvol=chan[i].rvol=isMuted[i]?0:chan[i].outVol&0xf; const unsigned char prevVolume=lastVolume; - lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].lvol&0xf)<<(i<<2)); + lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].resVol&0xf)<<(i<<2)); if (prevVolume!=lastVolume) { rWrite(0xc,lastVolume); } diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 4bd6d4f76..ef0359464 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -34,7 +34,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { int note; int panning, prevPan; bool active, insChanged, volumeChanged, freqChanged, keyOn, keyOff, inPorta, setPos; - int vol, outVol, lvol, rvol; + int vol, outVol, resVol, lvol, rvol; int macroVolMul; DivMacroInt std; void macroInit(DivInstrument* which) { @@ -64,6 +64,7 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { setPos(false), vol(15), outVol(15), + resVol(15), lvol(15), rvol(15), macroVolMul(64) {} diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index d62fcd5d2..165eb3909 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -1144,6 +1144,7 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" - prev: %d",ch->prevPan); ImGui::Text("- vol: %.2x",ch->vol); ImGui::Text("- outVol: %.2x",ch->outVol); + ImGui::Text("- resVol: %.2x",ch->resVol); ImGui::Text("- lvol: %.2x",ch->lvol); ImGui::Text("- rvol: %.2x",ch->rvol); ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); From 2bb08159383e1046d46b1aefa63fb2a7f4b37101 Mon Sep 17 00:00:00 2001 From: cam900 Date: Sun, 11 Dec 2022 17:11:44 +0900 Subject: [PATCH 19/36] ID conflict --- src/engine/sysDef.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 674344da3..d713a65b4 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1694,7 +1694,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_K007232]=new DivSysDef( - "Konami K007232", NULL, 0xc1, 0, 2, false, true, 0, false, 1U< Date: Tue, 13 Dec 2022 03:53:00 +0900 Subject: [PATCH 20/36] Fix forcing instrument --- src/engine/platform/k007232.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp index b4501df73..f7feaebcb 100644 --- a/src/engine/platform/k007232.cpp +++ b/src/engine/platform/k007232.cpp @@ -394,6 +394,7 @@ void DivPlatformK007232::muteChannel(int ch, bool mute) { } void DivPlatformK007232::forceIns() { + while (!writes.empty()) writes.pop(); for (int i=0; i<2; i++) { chan[i].insChanged=true; chan[i].freqChanged=true; From 5ff3d910cab3b8011a84dc420d627bab784e4556 Mon Sep 17 00:00:00 2001 From: cam900 Date: Tue, 13 Dec 2022 14:47:54 +0900 Subject: [PATCH 21/36] Sync with master --- src/engine/platform/k007232.h | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index ef0359464..3efcb3f35 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -26,15 +26,14 @@ #include "vgsound_emu/src/k007232/k007232.hpp" class DivPlatformK007232: public DivDispatch, public k007232_intf { - struct Channel { - int freq, prevFreq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannelFreq, public SharedChannelVolume { + int prevFreq; unsigned int audPos; int prevBank; - int sample, wave, ins; - int note; + int sample; int panning, prevPan; - bool active, insChanged, volumeChanged, freqChanged, keyOn, keyOff, inPorta, setPos; - int vol, outVol, resVol, lvol, rvol; + bool volumeChanged, setPos; + int resVol, lvol, rvol; int macroVolMul; DivMacroInt std; void macroInit(DivInstrument* which) { @@ -42,28 +41,16 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { pitch2=0; } Channel(): - freq(0), + SharedChannelFreq(), + SharedChannelVolume(15), prevFreq(-1), - baseFreq(0), - pitch(0), - pitch2(0), audPos(0), prevBank(-1), sample(-1), - ins(-1), - note(0), panning(255), prevPan(-1), - active(false), - insChanged(true), volumeChanged(false), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), setPos(false), - vol(15), - outVol(15), resVol(15), lvol(15), rvol(15), From 2ccc24920a00bf7b154f69fecb36c6a46688ad4b Mon Sep 17 00:00:00 2001 From: cam900 Date: Tue, 13 Dec 2022 16:25:38 +0900 Subject: [PATCH 22/36] Fix build --- src/gui/debug.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index 74aa6e38a..a1688177c 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -1146,7 +1146,6 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text("* Sample: %d",ch->sample); ImGui::Text(" - pos: %d",ch->audPos); ImGui::Text(" - prevBank: %d",ch->prevBank); - ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- ins: %d",ch->ins); ImGui::Text("* panning: %d",ch->panning); ImGui::Text(" - prev: %d",ch->prevPan); From ad6fd1561f5a40cdc197081c01da8a4e94860411 Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 14 Dec 2022 14:11:08 +0900 Subject: [PATCH 23/36] Sync with master --- src/engine/platform/k007232.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h index 3efcb3f35..6e020f9d8 100644 --- a/src/engine/platform/k007232.h +++ b/src/engine/platform/k007232.h @@ -26,7 +26,7 @@ #include "vgsound_emu/src/k007232/k007232.hpp" class DivPlatformK007232: public DivDispatch, public k007232_intf { - struct Channel: public SharedChannelFreq, public SharedChannelVolume { + struct Channel: public SharedChannel { int prevFreq; unsigned int audPos; int prevBank; @@ -35,14 +35,8 @@ class DivPlatformK007232: public DivDispatch, public k007232_intf { bool volumeChanged, setPos; int resVol, lvol, rvol; int macroVolMul; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - SharedChannelFreq(), - SharedChannelVolume(15), + SharedChannel(15), prevFreq(-1), audPos(0), prevBank(-1), From a7153f42e9d473c633613a09f0a5a20124c950a8 Mon Sep 17 00:00:00 2001 From: cam900 Date: Wed, 14 Dec 2022 14:16:46 +0900 Subject: [PATCH 24/36] Reduce debug duplication --- src/gui/debug.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/gui/debug.cpp b/src/gui/debug.cpp index da135ddd7..c32cc2f61 100644 --- a/src/gui/debug.cpp +++ b/src/gui/debug.cpp @@ -898,31 +898,19 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_K007232: { DivPlatformK007232::Channel* ch=(DivPlatformK007232::Channel*)data; ImGui::Text("> K007232"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - prev: %d",ch->prevFreq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("* note: %d",ch->note); + COMMON_CHAN_DEBUG; + ImGui::Text("- prevFreq: %d",ch->prevFreq); ImGui::Text("* Sample: %d",ch->sample); ImGui::Text(" - pos: %d",ch->audPos); ImGui::Text(" - prevBank: %d",ch->prevBank); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("* panning: %d",ch->panning); ImGui::Text(" - prev: %d",ch->prevPan); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- resVol: %.2x",ch->resVol); ImGui::Text("- lvol: %.2x",ch->lvol); ImGui::Text("- rvol: %.2x",ch->rvol); ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->volumeChanged?colorOn:colorOff,">> VolumeChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); break; } From 2a068ca046ce22587b66a61a76067d4fed272903 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 16:23:47 -0500 Subject: [PATCH 25/36] YM2151: re-enable timer emulation in Nuked-OPM --- extern/opm/opm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/extern/opm/opm.c b/extern/opm/opm.c index aafce483d..d2878f541 100644 --- a/extern/opm/opm.c +++ b/extern/opm/opm.c @@ -1892,9 +1892,9 @@ void OPM_Clock(opm_t *chip, int32_t *output, uint8_t *sh1, uint8_t *sh2, uint8_t OPM_PhaseCalcIncrement(chip); OPM_PhaseCalcFNumBlock(chip); - /*OPM_DoTimerIRQ(chip); + OPM_DoTimerIRQ(chip); OPM_DoTimerA(chip); - OPM_DoTimerB(chip);*/ + OPM_DoTimerB(chip); OPM_DoLFOMult(chip); OPM_DoLFO1(chip); OPM_Noise(chip); @@ -1904,10 +1904,10 @@ void OPM_Clock(opm_t *chip, int32_t *output, uint8_t *sh1, uint8_t *sh2, uint8_t OPM_NoiseTimer(chip); OPM_KeyOn1(chip); OPM_DoIO(chip); - /*OPM_DoTimerA2(chip); - OPM_DoTimerB2(chip);*/ + OPM_DoTimerA2(chip); + OPM_DoTimerB2(chip); OPM_DoLFO2(chip); - //OPM_CSM(chip); + OPM_CSM(chip); OPM_NoiseChannel(chip); OPM_Output(chip); OPM_DAC(chip); From 77320314042c3a7d41ddd2c10c40a1780d676157 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 17:07:46 -0500 Subject: [PATCH 26/36] update ymfm --- src/engine/platform/sound/ymfm/ymfm.h | 81 +++++++++++++ src/engine/platform/sound/ymfm/ymfm_adpcm.cpp | 107 +++++++++++------- src/engine/platform/sound/ymfm/ymfm_adpcm.h | 8 +- src/engine/platform/sound/ymfm/ymfm_fm.h | 19 +++- src/engine/platform/sound/ymfm/ymfm_fm.ipp | 73 +++++++----- src/engine/platform/sound/ymfm/ymfm_opm.h | 2 +- src/engine/platform/sound/ymfm/ymfm_opn.cpp | 25 +++- src/engine/platform/sound/ymfm/ymfm_opn.h | 2 +- src/engine/platform/sound/ymfm/ymfm_ssg.cpp | 13 +-- src/engine/platform/sound/ymfm/ymfm_ssg.h | 4 +- 10 files changed, 237 insertions(+), 97 deletions(-) diff --git a/src/engine/platform/sound/ymfm/ymfm.h b/src/engine/platform/sound/ymfm/ymfm.h index 7b98f8499..47ff90072 100644 --- a/src/engine/platform/sound/ymfm/ymfm.h +++ b/src/engine/platform/sound/ymfm/ymfm.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -325,6 +326,86 @@ struct ymfm_output }; +// ======================> ymfm_wavfile + +// this class is a debugging helper that accumulates data and writes it to wav files +template +class ymfm_wavfile +{ +public: + // construction + ymfm_wavfile(uint32_t samplerate = 44100) : + m_samplerate(samplerate) + { + } + + // configuration + ymfm_wavfile &set_index(uint32_t index) { m_index = index; return *this; } + ymfm_wavfile &set_samplerate(uint32_t samplerate) { m_samplerate = samplerate; return *this; } + + // destruction + ~ymfm_wavfile() + { + if (!m_buffer.empty()) + { + // create file + char name[20]; + sprintf(name, "wavlog-%02d.wav", m_index); + FILE *out = fopen(name, "wb"); + + // make the wav file header + uint8_t header[44]; + memcpy(&header[0], "RIFF", 4); + *(uint32_t *)&header[4] = m_buffer.size() * 2 + 44 - 8; + memcpy(&header[8], "WAVE", 4); + memcpy(&header[12], "fmt ", 4); + *(uint32_t *)&header[16] = 16; + *(uint16_t *)&header[20] = 1; + *(uint16_t *)&header[22] = Channels; + *(uint32_t *)&header[24] = m_samplerate; + *(uint32_t *)&header[28] = m_samplerate * 2 * Channels; + *(uint16_t *)&header[32] = 2 * Channels; + *(uint16_t *)&header[34] = 16; + memcpy(&header[36], "data", 4); + *(uint32_t *)&header[40] = m_buffer.size() * 2 + 44 - 44; + + // write header then data + fwrite(&header[0], 1, sizeof(header), out); + fwrite(&m_buffer[0], 2, m_buffer.size(), out); + fclose(out); + } + } + + // add data to the file + template + void add(ymfm_output output) + { + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index]; + for (int index = 0; index < Channels; index++) + m_buffer.push_back(sum[index]); + } + + // add data to the file, using a reference + template + void add(ymfm_output output, ymfm_output const &ref) + { + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index] - ref.data[index]; + for (int index = 0; index < Channels; index++) + m_buffer.push_back(sum[index]); + } + +private: + // internal state + uint32_t m_index; + uint32_t m_samplerate; + std::vector m_buffer; +}; + + // ======================> ymfm_saved_state // this class contains a managed vector of bytes that is used to save and diff --git a/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp b/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp index 76839e787..6d7eb710c 100644 --- a/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp @@ -465,48 +465,60 @@ void adpcm_b_channel::clock() if (position < 0x10000) return; - // if playing from RAM/ROM, check the end address and process - if (m_regs.external()) + // if we're about to process nibble 0, fetch sample + if (m_curnibble == 0) { - // wrap at the limit address - if (at_limit()) - m_curaddress = 0; - - // handle the sample end, either repeating or stopping - if (at_end()) - { - // if repeating, go back to the start - if (m_regs.repeat()) - load_start(); - - // otherwise, done; set the EOS bit and return - else - { - m_accumulator = 0; - m_prev_accum = 0; - m_status = (m_status & ~STATUS_PLAYING) | STATUS_EOS; - debug::log_keyon("%s\n", "ADPCM EOS"); - return; - } - } - - // if we're about to process nibble 0, fetch and increment - if (m_curnibble == 0) - { - m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress++); - m_curaddress &= 0xffffff; - } + // playing from RAM/ROM + if (m_regs.external()) + m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress); } // extract the nibble from our current byte uint8_t data = uint8_t(m_curbyte << (4 * m_curnibble)) >> 4; m_curnibble ^= 1; - // if CPU-driven and we just processed the last nibble, copy the next byte and request more - if (m_curnibble == 0 && !m_regs.external()) + // we just processed the last nibble + if (m_curnibble == 0) { - m_curbyte = m_regs.cpudata(); - m_status |= STATUS_BRDY; + // if playing from RAM/ROM, check the end/limit address or advance + if (m_regs.external()) + { + // handle the sample end, either repeating or stopping + if (at_end()) + { + // if repeating, go back to the start + if (m_regs.repeat()) + load_start(); + + // otherwise, done; set the EOS bit + else + { + m_accumulator = 0; + m_prev_accum = 0; + m_status = (m_status & ~STATUS_PLAYING) | STATUS_EOS; + debug::log_keyon("%s\n", "ADPCM EOS"); + return; + } + } + + // wrap at the limit address + else if (at_limit()) + m_curaddress = 0; + + // otherwise, advance the current address + else + { + m_curaddress++; + m_curaddress &= 0xffffff; + } + } + + // if CPU-driven, copy the next byte and request more + else + { + m_curbyte = m_regs.cpudata(); + m_status |= STATUS_BRDY; + } } // remember previous value for interpolation @@ -574,18 +586,27 @@ uint8_t adpcm_b_channel::read(uint32_t regnum) m_dummy_read--; } - // did we hit the end? if so, signal EOS - if (at_end()) - { - m_status = STATUS_EOS | STATUS_BRDY; - debug::log_keyon("%s\n", "ADPCM EOS"); - } - - // otherwise, write the data and signal ready + // read the data else { + // read from outside of the chip result = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress++); - m_status = STATUS_BRDY; + + // did we hit the end? if so, signal EOS + if (at_end()) + { + m_status = STATUS_EOS | STATUS_BRDY; + debug::log_keyon("%s\n", "ADPCM EOS"); + } + else + { + // signal ready + m_status = STATUS_BRDY; + } + + // wrap at the limit address + if (at_limit()) + m_curaddress = 0; } } return result; diff --git a/src/engine/platform/sound/ymfm/ymfm_adpcm.h b/src/engine/platform/sound/ymfm/ymfm_adpcm.h index 58bee8a22..f80e6ab9e 100644 --- a/src/engine/platform/sound/ymfm/ymfm_adpcm.h +++ b/src/engine/platform/sound/ymfm/ymfm_adpcm.h @@ -351,11 +351,11 @@ private: // load the start address void load_start(); - // limit checker - bool at_limit() const { return (m_curaddress >> address_shift()) >= m_regs.limit(); } + // limit checker; stops at the last byte of the chunk described by address_shift() + bool at_limit() const { return (m_curaddress == (((m_regs.limit() + 1) << address_shift()) - 1)); } - // end checker - bool at_end() const { return (m_curaddress >> address_shift()) > m_regs.end(); } + // end checker; stops at the last byte of the chunk described by address_shift() + bool at_end() const { return (m_curaddress == (((m_regs.end() + 1) << address_shift()) - 1)); } // internal state uint32_t const m_address_shift; // address bits shift-left diff --git a/src/engine/platform/sound/ymfm/ymfm_fm.h b/src/engine/platform/sound/ymfm/ymfm_fm.h index 352ac9464..df3b486af 100644 --- a/src/engine/platform/sound/ymfm/ymfm_fm.h +++ b/src/engine/platform/sound/ymfm/ymfm_fm.h @@ -33,6 +33,8 @@ #pragma once +#define YMFM_DEBUG_LOG_WAVFILES (0) + namespace ymfm { @@ -162,8 +164,8 @@ template class fm_engine_base; template class fm_operator { - // "quiet" value, used to optimize when we can skip doing working - static constexpr uint32_t EG_QUIET = 0x200; + // "quiet" value, used to optimize when we can skip doing work + static constexpr uint32_t EG_QUIET = 0x380; public: // constructor @@ -206,6 +208,7 @@ public: // simple getters for debugging envelope_state debug_eg_state() const { return m_env_state; } uint16_t debug_eg_attenuation() const { return m_env_attenuation; } + uint8_t debug_ssg_inverted() const { return m_ssg_inverted; } opdata_cache &debug_cache() { return m_cache; } private: @@ -406,7 +409,14 @@ public: void set_clock_prescale(uint32_t prescale) { m_clock_prescale = prescale; } // compute sample rate - uint32_t sample_rate(uint32_t baseclock) const { return baseclock / (m_clock_prescale * OPERATORS); } + uint32_t sample_rate(uint32_t baseclock) const + { +#if (YMFM_DEBUG_LOG_WAVFILES) + for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) + m_wavfile[chnum].set_samplerate(baseclock / (m_clock_prescale * OPERATORS)); +#endif + return baseclock / (m_clock_prescale * OPERATORS); + } // return the owning device ymfm_interface &intf() const { return m_intf; } @@ -453,6 +463,9 @@ protected: RegisterType m_regs; // register accessor std::unique_ptr> m_channel[CHANNELS]; // channel pointers std::unique_ptr> m_operator[OPERATORS]; // operator pointers +#if (YMFM_DEBUG_LOG_WAVFILES) + mutable ymfm_wavfile<1> m_wavfile[CHANNELS]; // for debugging +#endif }; } diff --git a/src/engine/platform/sound/ymfm/ymfm_fm.ipp b/src/engine/platform/sound/ymfm/ymfm_fm.ipp index d532d7b2e..6eab8308b 100644 --- a/src/engine/platform/sound/ymfm/ymfm_fm.ipp +++ b/src/engine/platform/sound/ymfm/ymfm_fm.ipp @@ -448,6 +448,8 @@ void fm_operator::clock(uint32_t env_counter, int32_t lfo_raw_pm) // clock the SSG-EG state (OPN/OPNA) if (m_regs.op_ssg_eg_enable(m_opoffs)) clock_ssg_eg_state(); + else + m_ssg_inverted = false; // clock the envelope if on an envelope cycle; env_counter is a x.2 value if (bitfield(env_counter, 0, 2) == 0) @@ -470,15 +472,6 @@ int32_t fm_operator::compute_volume(uint32_t phase, uint32_t am_of // the low 10 bits of phase represents a full 2*PI period over // the full sin wave -#if 0 -// temporary envelope logging -if (m_choffs == 0) -{ - printf(" %c@%02X:%03X", "PADSRV"[m_env_state], m_cache.eg_rate[m_env_state], envelope_attenuation(am_offset)); - if (m_opoffs == 0x18) printf("\n"); -} -#endif - // early out if the envelope is effectively off if (m_env_attenuation > EG_QUIET && m_cache.eg_shift == 0) return 0; @@ -896,6 +889,23 @@ void fm_channel::clock(uint32_t env_counter, int32_t lfo_raw_pm) for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++) if (m_op[opnum] != nullptr) m_op[opnum]->clock(env_counter, lfo_raw_pm); + +/* +useful temporary code for envelope debugging +if (m_choffs == 0x101) +{ + for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++) + { + auto &op = *m_op[((opnum & 1) << 1) | ((opnum >> 1) & 1)]; + printf(" %c%03X%c%c ", + "PADSRV"[op.debug_eg_state()], + op.debug_eg_attenuation(), + op.debug_ssg_inverted() ? '-' : '+', + m_regs.op_ssg_eg_enable(op.opoffs()) ? '0' + m_regs.op_ssg_eg_mode(op.opoffs()) : ' '); + } +printf(" -- "); +} +*/ } @@ -943,7 +953,8 @@ void fm_channel::output_2op(output_data &output, uint32_t rshift, } else { - result = op1value + (m_op[1]->compute_volume(m_op[1]->phase(), am_offset) >> rshift); + result = (RegisterType::MODULATOR_DELAY ? m_feedback[1] : op1value) >> rshift; + result += m_op[1]->compute_volume(m_op[1]->phase(), am_offset) >> rshift; int32_t clipmin = -clipmax - 1; result = clamp(result, clipmin, clipmax); } @@ -1180,6 +1191,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : m_irq_mask(STATUS_TIMERA | STATUS_TIMERB), m_irq_state(0), m_timer_running{0,0}, + m_total_clocks(0), m_active_channels(ALL_CHANNELS), m_modified_channels(ALL_CHANNELS), m_prepare_count(0) @@ -1195,6 +1207,11 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : for (uint32_t opnum = 0; opnum < OPERATORS; opnum++) m_operator[opnum] = std::make_unique>(*this, RegisterType::operator_offset(opnum)); +#if (YMFM_DEBUG_LOG_WAVFILES) + for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) + m_wavfile[chnum].set_index(chnum); +#endif + // do the initial operator assignment assign_operators(); } @@ -1305,24 +1322,6 @@ uint32_t fm_engine_base::clock(uint32_t chanmask) if (bitfield(chanmask, chnum)) m_channel[chnum]->clock(m_env_counter, lfo_raw_pm); -#if 0 -//Temporary debugging... -static double curtime = 0; -//for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) -uint32_t chnum = 4; -{ - printf("t=%.4f ch%d: ", curtime, chnum); - for (uint32_t opnum = 0; opnum < 4; opnum++) - { - auto op = debug_channel(chnum)->debug_operator(opnum); - auto eg_state = op->debug_eg_state(); - printf(" %c%03X[%02X]%c ", "PADSRV"[eg_state], op.debug_eg_attenuation(), op.debug_cache().eg_rate[eg_state], m_regs.op_ssg_eg_enable(op.opoffs()) ? '*' : ' '); - } - printf(" -- "); -} -curtime += 1.0 / double(sample_rate(7670454)); -#endif - // return the envelope counter as it is used to clock ADPCM-A return m_env_counter; } @@ -1340,7 +1339,8 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, chanmask &= debug::GLOBAL_FM_CHANNEL_MASK; // mask out inactive channels - chanmask &= m_active_channels; + if (!YMFM_DEBUG_LOG_WAVFILES) + chanmask &= m_active_channels; // handle the rhythm case, where some of the operators are dedicated // to percussion (this is an OPL-specific feature) @@ -1358,6 +1358,9 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { +#if (YMFM_DEBUG_LOG_WAVFILES) + auto reference = output; +#endif if (chnum == 6) m_channel[chnum]->output_rhythm_ch6(output, rshift, clipmax); else if (chnum == 7) @@ -1368,6 +1371,9 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); +#if (YMFM_DEBUG_LOG_WAVFILES) + m_wavfile[chnum].add(output, reference); +#endif } } else @@ -1376,10 +1382,16 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { +#if (YMFM_DEBUG_LOG_WAVFILES) + auto reference = output; +#endif if (m_channel[chnum]->is4op()) m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); +#if (YMFM_DEBUG_LOG_WAVFILES) + m_wavfile[chnum].add(output, reference); +#endif } } } @@ -1508,7 +1520,10 @@ void fm_engine_base::engine_timer_expired(uint32_t tnum) if (tnum == 0 && m_regs.csm()) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(RegisterType::CSM_TRIGGER_MASK, chnum)) + { m_channel[chnum]->keyonoff(1, KEYON_CSM, chnum); + m_modified_channels |= 1 << chnum; + } // reset m_timer_running[tnum] = false; diff --git a/src/engine/platform/sound/ymfm/ymfm_opm.h b/src/engine/platform/sound/ymfm/ymfm_opm.h index 830b195e4..2034b5f4f 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opm.h +++ b/src/engine/platform/sound/ymfm/ymfm_opm.h @@ -174,7 +174,7 @@ public: // system-wide registers uint32_t test() const { return byte(0x01, 0, 8); } uint32_t lfo_reset() const { return byte(0x01, 1, 1); } - uint32_t noise_frequency() const { return byte(0x0f, 0, 5); } + uint32_t noise_frequency() const { return byte(0x0f, 0, 5) ^ 0x1f; } uint32_t noise_enable() const { return byte(0x0f, 7, 1); } uint32_t timer_a_value() const { return word(0x10, 0, 8, 0x11, 0, 2); } uint32_t timer_b_value() const { return byte(0x12, 0, 8); } diff --git a/src/engine/platform/sound/ymfm/ymfm_opn.cpp b/src/engine/platform/sound/ymfm/ymfm_opn.cpp index 00ac2cf63..053ad9770 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opn.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_opn.cpp @@ -146,7 +146,10 @@ bool opn_registers_base::write(uint16_t index, uint8_t data, uint32_t &c // borrow unused registers 0xb8-bf/0x1b8-bf as temporary holding locations if ((index & 0xf0) == 0xa0) { - uint32_t latchindex = 0xb8 | (bitfield(index, 3) << 2) | bitfield(index, 0, 2); + if (bitfield(index, 0, 2) == 3) + return false; + + uint32_t latchindex = 0xb8 | bitfield(index, 3); if (IsOpnA) latchindex |= index & 0x100; @@ -157,9 +160,16 @@ bool opn_registers_base::write(uint16_t index, uint8_t data, uint32_t &c // writes to the lower half only commit if the latch is there else if (bitfield(m_regdata[latchindex], 7)) { + m_regdata[index] = data; m_regdata[index | 4] = m_regdata[latchindex] & 0x3f; m_regdata[latchindex] = 0; } + return false; + } + else if ((index & 0xf8) == 0xb8) + { + // registers 0xb8-0xbf are used internally + return false; } // everything else is normal @@ -195,7 +205,12 @@ int32_t opn_registers_base::clock_noise_and_lfo() if (!IsOpnA || !lfo_enable()) { m_lfo_counter = 0; - m_lfo_am = 0; + + // special case: if LFO is disabled on OPNA, it basically just keeps the counter + // at 0; since position 0 gives an AM value of 0x3f, it is important to reflect + // that here; for example, MegaDrive Venom plays some notes with LFO globally + // disabled but enabling LFO on the operators, and it expects this added attenutation + m_lfo_am = IsOpnA ? 0x3f : 0x00; return 0; } @@ -417,10 +432,10 @@ std::string opn_registers_base::log_keyon(uint32_t choffs, uint32_t opof ch_output_1(choffs) ? 'R' : '-'); if (op_ssg_eg_enable(opoffs)) end += sprintf(end, " ssg=%X", op_ssg_eg_mode(opoffs)); - bool am = (lfo_enable() && op_lfo_am_enable(opoffs) && ch_lfo_am_sens(choffs) != 0); + bool am = (op_lfo_am_enable(opoffs) && ch_lfo_am_sens(choffs) != 0); if (am) end += sprintf(end, " am=%u", ch_lfo_am_sens(choffs)); - bool pm = (lfo_enable() && ch_lfo_pm_sens(choffs) != 0); + bool pm = (ch_lfo_pm_sens(choffs) != 0); if (pm) end += sprintf(end, " pm=%u", ch_lfo_pm_sens(choffs)); if (am || pm) @@ -1094,7 +1109,7 @@ uint8_t ym2608::read_status_hi() uint8_t ym2608::read_data_hi() { uint8_t result = 0; - if (m_address < 0x10) + if ((m_address & 0xff) < 0x10) { // 00-0F: Read from ADPCM-B result = m_adpcm_b.read(m_address & 0x0f); diff --git a/src/engine/platform/sound/ymfm/ymfm_opn.h b/src/engine/platform/sound/ymfm/ymfm_opn.h index 00fd61adf..2a9b92d5d 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opn.h +++ b/src/engine/platform/sound/ymfm/ymfm_opn.h @@ -784,7 +784,7 @@ public: protected: // simulate the DAC discontinuity - int32_t dac_discontinuity(int32_t value) const { return (value < 0) ? (value - 2) : (value + 3); } + int32_t dac_discontinuity(int32_t value) const { return (value < 0) ? (value - 3) : (value + 4); } // internal state uint16_t m_address; // address register diff --git a/src/engine/platform/sound/ymfm/ymfm_ssg.cpp b/src/engine/platform/sound/ymfm/ymfm_ssg.cpp index 5a9a9d43e..77a62563b 100644 --- a/src/engine/platform/sound/ymfm/ymfm_ssg.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_ssg.cpp @@ -201,19 +201,14 @@ void ssg_engine::output(output_data &output) for (int chan = 0; chan < 3; chan++) { // noise depends on the noise state, which is the LSB of m_noise_state - uint32_t noise_on = m_regs.ch_noise_enable(chan) & m_noise_state; + uint32_t noise_on = m_regs.ch_noise_enable_n(chan) | m_noise_state; // tone depends on the current tone state - uint32_t tone_on = m_regs.ch_tone_enable(chan) & m_tone_state[chan]; + uint32_t tone_on = m_regs.ch_tone_enable_n(chan) | m_tone_state[chan]; - // if envelope is enabled but tone and noise aren't, use the envelope - // volume + // if neither tone nor noise enabled, return 0 uint32_t volume; - if (m_regs.ch_envelope_enable(chan) && !m_regs.ch_noise_enable(chan) && !m_regs.ch_tone_enable(chan)) - volume = envelope_volume; - - // if neither tone nor noise enabled, return 0 - else if ((noise_on | tone_on) == 0) + if ((noise_on & tone_on) == 0) volume = 0; // if the envelope is enabled, use its amplitude diff --git a/src/engine/platform/sound/ymfm/ymfm_ssg.h b/src/engine/platform/sound/ymfm/ymfm_ssg.h index 55e748d6b..df974fe43 100644 --- a/src/engine/platform/sound/ymfm/ymfm_ssg.h +++ b/src/engine/platform/sound/ymfm/ymfm_ssg.h @@ -130,8 +130,8 @@ public: uint32_t io_b_data() const { return m_regdata[0x0f]; } // per-channel registers - uint32_t ch_noise_enable(uint32_t choffs) const { return bitfield(~m_regdata[0x07], 3 + choffs); } - uint32_t ch_tone_enable(uint32_t choffs) const { return bitfield(~m_regdata[0x07], 0 + choffs); } + uint32_t ch_noise_enable_n(uint32_t choffs) const { return bitfield(m_regdata[0x07], 3 + choffs); } + uint32_t ch_tone_enable_n(uint32_t choffs) const { return bitfield(m_regdata[0x07], 0 + choffs); } uint32_t ch_tone_period(uint32_t choffs) const { return m_regdata[0x00 + 2 * choffs] | (bitfield(m_regdata[0x01 + 2 * choffs], 0, 4) << 8); } uint32_t ch_envelope_enable(uint32_t choffs) const { return bitfield(m_regdata[0x08 + choffs], 4); } uint32_t ch_amplitude(uint32_t choffs) const { return bitfield(m_regdata[0x08 + choffs], 0, 4); } From 332c6edbedb871dedf29bc291cda356315ec56c4 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 17:18:19 -0500 Subject: [PATCH 27/36] re-initialize dispatch if core settings changed --- src/engine/engine.cpp | 6 +++++- src/engine/engine.h | 2 +- src/gui/settings.cpp | 11 ++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 430bcc943..8e684ddaf 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -3916,9 +3916,13 @@ void DivEngine::setConsoleMode(bool enable) { consoleMode=enable; } -bool DivEngine::switchMaster() { +bool DivEngine::switchMaster(bool full) { logI("switching output..."); deinitAudioBackend(true); + if (full) { + quitDispatch(); + initDispatch(); + } if (initAudioBackend()) { for (int i=0; igetConfString("tg100Path","") || settings.mu5Path!=e->getConfString("mu5Path",""); + bool coresChanged=( + settings.arcadeCore!=e->getConfInt("arcadeCore",0) || + settings.ym2612Core!=e->getConfInt("ym2612Core",0) || + settings.snCore!=e->getConfInt("snCore",0) || + settings.nesCore!=e->getConfInt("nesCore",0) || + settings.fdsCore!=e->getConfInt("fdsCore",0) || + settings.c64Core!=e->getConfInt("c64Core",1) + ); + e->setConf("mainFontSize",settings.mainFontSize); e->setConf("patFontSize",settings.patFontSize); e->setConf("iconSize",settings.iconSize); @@ -2754,7 +2763,7 @@ void FurnaceGUI::commitSettings() { } } - if (!e->switchMaster()) { + if (!e->switchMaster(coresChanged)) { showError("could not initialize audio!"); } From f13271750236230d9a1eb1877cd99845673e102d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 19:09:50 -0500 Subject: [PATCH 28/36] YM2612: prepare to implement CSM on ymfm --- src/engine/platform/genesis.cpp | 18 ++++++++++++++++++ src/engine/platform/genesis.h | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index adfdf2583..1f79cd0d4 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -19,6 +19,7 @@ #include "genesis.h" #include "../engine.h" +#include "../../ta-log.h" #include #include @@ -27,6 +28,22 @@ #define IS_REALLY_MUTED(x) (isMuted[x] && (x<5 || !softPCM || (isMuted[5] && isMuted[6]))) +void DivYM2612Interface::ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks) { + if (tnum==1) { + countB=duration_in_clocks; + } else if (tnum==0) { + countA=duration_in_clocks; + } + logV("ymfm_set_timer(%d,%d)",tnum,duration_in_clocks); +} + +void DivYM2612Interface::clock() { + if (countA>=0) { + countA-=144; + if (countA<0) m_engine->engine_timer_expired(0); + } +} + void DivPlatformGenesis::processDAC(int iRate) { if (softPCM) { softPCMTimer+=chipClock/576; @@ -192,6 +209,7 @@ void DivPlatformGenesis::acquire_ymfm(short* bufL, short* bufR, size_t start, si lastBusy=1; } + iface.clock(); if (ladder) { fm_ymfm->generate(&out_ymfm); } else { diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index ac2e54323..bd5d9afff 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -26,7 +26,15 @@ class DivYM2612Interface: public ymfm::ymfm_interface { + int countA, countB; + public: + void clock(); + void ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks); + DivYM2612Interface(): + ymfm::ymfm_interface(), + countA(-1), + countB(-1) {} }; class DivPlatformGenesis: public DivPlatformOPN { From 2f8e2f9a5e062f880bfe5f504cc473796572f408 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 19:22:34 -0500 Subject: [PATCH 29/36] YM2612: partial, buggy CSM on ymfm --- src/engine/platform/genesis.cpp | 2 +- src/engine/platform/sound/ymfm/ymfm_fm.ipp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index 1f79cd0d4..9dd3699c7 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -209,12 +209,12 @@ void DivPlatformGenesis::acquire_ymfm(short* bufL, short* bufR, size_t start, si lastBusy=1; } - iface.clock(); if (ladder) { fm_ymfm->generate(&out_ymfm); } else { ((ymfm::ym3438*)fm_ymfm)->generate(&out_ymfm); } + iface.clock(); os[0]=out_ymfm.data[0]; os[1]=out_ymfm.data[1]; //OPN2_Write(&fm,0,0); diff --git a/src/engine/platform/sound/ymfm/ymfm_fm.ipp b/src/engine/platform/sound/ymfm/ymfm_fm.ipp index 6eab8308b..4fdff8a38 100644 --- a/src/engine/platform/sound/ymfm/ymfm_fm.ipp +++ b/src/engine/platform/sound/ymfm/ymfm_fm.ipp @@ -1521,7 +1521,7 @@ void fm_engine_base::engine_timer_expired(uint32_t tnum) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(RegisterType::CSM_TRIGGER_MASK, chnum)) { - m_channel[chnum]->keyonoff(1, KEYON_CSM, chnum); + m_channel[chnum]->keyonoff(0xf, KEYON_CSM, chnum); m_modified_channels |= 1 << chnum; } From d53cc328780558dd29f40a5a3fda31a4b3bfa84a Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 23:16:24 -0500 Subject: [PATCH 30/36] update SDL to 2.24.2 not updating to 2.26.1 due to build failure see https://github.com/libsdl-org/SDL/issues/6169 --- .gitmodules | 1 - extern/SDL | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 83f383989..5f0e538d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,6 @@ [submodule "extern/SDL"] path = extern/SDL url = https://github.com/libsdl-org/SDL.git - branch = 2.0.22 [submodule "extern/libsndfile"] path = extern/libsndfile url = https://github.com/libsndfile/libsndfile.git diff --git a/extern/SDL b/extern/SDL index f8e14ad25..55b03c749 160000 --- a/extern/SDL +++ b/extern/SDL @@ -1 +1 @@ -Subproject commit f8e14ad25aa6f0b4bbed411583a9863c855ad9e6 +Subproject commit 55b03c7493a7abed33cf803d1380a40fa8af903f From 0b66595c0fdffd0156ef9131d49c5ec09e0c6f3e Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 23:27:17 -0500 Subject: [PATCH 31/36] update Android project template --- .../java/org/libsdl/app/HIDDeviceManager.java | 4 + .../main/java/org/libsdl/app/SDLActivity.java | 161 ++++++++++++++++-- .../org/libsdl/app/SDLControllerManager.java | 36 ++-- 3 files changed, 170 insertions(+), 31 deletions(-) diff --git a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 802c7254e..cf3c9267f 100644 --- a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -248,7 +248,9 @@ public class HIDDeviceManager { 0x1689, // Razer Onza 0x1949, // Lab126, Inc. 0x1bad, // Harmonix + 0x20d6, // PowerA 0x24c6, // PowerA + 0x2c22, // Qanba }; if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC && @@ -274,7 +276,9 @@ public class HIDDeviceManager { 0x0e6f, // PDP 0x0f0d, // Hori 0x1532, // Razer Wildcat + 0x20d6, // PowerA 0x24c6, // PowerA + 0x2dc8, /* 8BitDo */ 0x2e24, // Hyperkin }; diff --git a/android/app/src/main/java/org/libsdl/app/SDLActivity.java b/android/app/src/main/java/org/libsdl/app/SDLActivity.java index 3da072091..55b961a47 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -27,7 +27,9 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.text.Editable; import android.text.InputType; +import android.text.Selection; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -63,6 +65,112 @@ import java.util.Locale; */ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { private static final String TAG = "SDL"; +/* + // Display InputType.SOURCE/CLASS of events and devices + // + // SDLActivity.debugSource(device.getSources(), "device[" + device.getName() + "]"); + // SDLActivity.debugSource(event.getSource(), "event"); + public static void debugSource(int sources, String prefix) { + int s = sources; + int s_copy = sources; + String cls = ""; + String src = ""; + int tst = 0; + int FLAG_TAINTED = 0x80000000; + + if ((s & InputDevice.SOURCE_CLASS_BUTTON) != 0) cls += " BUTTON"; + if ((s & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) cls += " JOYSTICK"; + if ((s & InputDevice.SOURCE_CLASS_POINTER) != 0) cls += " POINTER"; + if ((s & InputDevice.SOURCE_CLASS_POSITION) != 0) cls += " POSITION"; + if ((s & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) cls += " TRACKBALL"; + + + int s2 = s_copy & ~InputDevice.SOURCE_ANY; // keep class bits + s2 &= ~( InputDevice.SOURCE_CLASS_BUTTON + | InputDevice.SOURCE_CLASS_JOYSTICK + | InputDevice.SOURCE_CLASS_POINTER + | InputDevice.SOURCE_CLASS_POSITION + | InputDevice.SOURCE_CLASS_TRACKBALL); + + if (s2 != 0) cls += "Some_Unkown"; + + s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + tst = InputDevice.SOURCE_BLUETOOTH_STYLUS; + if ((s & tst) == tst) src += " BLUETOOTH_STYLUS"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_DPAD; + if ((s & tst) == tst) src += " DPAD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_GAMEPAD; + if ((s & tst) == tst) src += " GAMEPAD"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + tst = InputDevice.SOURCE_HDMI; + if ((s & tst) == tst) src += " HDMI"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_JOYSTICK; + if ((s & tst) == tst) src += " JOYSTICK"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_KEYBOARD; + if ((s & tst) == tst) src += " KEYBOARD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_MOUSE; + if ((s & tst) == tst) src += " MOUSE"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= 26) { + tst = InputDevice.SOURCE_MOUSE_RELATIVE; + if ((s & tst) == tst) src += " MOUSE_RELATIVE"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_ROTARY_ENCODER; + if ((s & tst) == tst) src += " ROTARY_ENCODER"; + s2 &= ~tst; + } + tst = InputDevice.SOURCE_STYLUS; + if ((s & tst) == tst) src += " STYLUS"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_TOUCHPAD; + if ((s & tst) == tst) src += " TOUCHPAD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_TOUCHSCREEN; + if ((s & tst) == tst) src += " TOUCHSCREEN"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + tst = InputDevice.SOURCE_TOUCH_NAVIGATION; + if ((s & tst) == tst) src += " TOUCH_NAVIGATION"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_TRACKBALL; + if ((s & tst) == tst) src += " TRACKBALL"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_ANY; + if ((s & tst) == tst) src += " ANY"; + s2 &= ~tst; + + if (s == FLAG_TAINTED) src += " FLAG_TAINTED"; + s2 &= ~FLAG_TAINTED; + + if (s2 != 0) src += " Some_Unkown"; + + Log.v(TAG, prefix + "int=" + s_copy + " CLASS={" + cls + " } source(s):" + src); + } +*/ public static boolean mIsResumedCalled, mHasFocus; public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24); @@ -1204,8 +1312,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh for (int id : ids) { InputDevice device = InputDevice.getDevice(id); - if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { - nativeAddTouch(device.getId(), device.getName()); + /* Allow SOURCE_TOUCHSCREEN and also Virtual InputDevices because they can send TOUCHSCREEN events */ + if (device != null && ((device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN + || device.isVirtual())) { + + int touchDevId = device.getId(); + /* + * Prevent id to be -1, since it's used in SDL internal for synthetic events + * Appears when using Android emulator, eg: + * adb shell input mouse tap 100 100 + * adb shell input touchscreen tap 100 100 + */ + if (touchDevId < 0) { + touchDevId -= 1; + } + nativeAddTouch(touchDevId, device.getName()); } } } @@ -1895,7 +2016,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } - if ((source & InputDevice.SOURCE_KEYBOARD) != 0) { + if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (SDLActivity.isTextInputEvent(event)) { SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); @@ -1908,7 +2029,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } - if ((source & InputDevice.SOURCE_MOUSE) != 0) { + if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses // they are ignored here because sending them as mouse input to SDL is messy if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { @@ -2195,7 +2316,7 @@ class DummyEdit extends View implements View.OnKeyListener { public InputConnection onCreateInputConnection(EditorInfo outAttrs) { ic = new SDLInputConnection(this, true); - outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; + outAttrs.inputType = InputType.TYPE_CLASS_TEXT; outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */; @@ -2237,6 +2358,29 @@ class SDLInputConnection extends BaseInputConnection { @Override public boolean commitText(CharSequence text, int newCursorPosition) { + /* Generate backspaces for the text we're going to replace */ + final Editable content = getEditable(); + if (content != null) { + int a = getComposingSpanStart(content); + int b = getComposingSpanEnd(content); + if (a == -1 || b == -1) { + a = Selection.getSelectionStart(content); + b = Selection.getSelectionEnd(content); + } + if (a < 0) a = 0; + if (b < 0) b = 0; + if (b < a) { + int tmp = a; + a = b; + b = tmp; + } + int backspaces = (b - a); + + for (int i = 0; i < backspaces; i++) { + nativeGenerateScancodeForUnichar('\b'); + } + } + for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c == '\n') { @@ -2271,14 +2415,11 @@ class SDLInputConnection extends BaseInputConnection { // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265 if (beforeLength > 0 && afterLength == 0) { - boolean ret = true; // backspace(s) while (beforeLength-- > 0) { - boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) - && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)); - ret = ret && ret_key; + nativeGenerateScancodeForUnichar('\b'); } - return ret; + return true; } return super.deleteSurroundingText(beforeLength, afterLength); diff --git a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 1fa32ef39..82373d9d6 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -255,23 +255,21 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler { @Override public boolean handleMotionEvent(MotionEvent event) { - if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) { - int actionPointerIndex = event.getActionIndex(); - int action = event.getActionMasked(); - if (action == MotionEvent.ACTION_MOVE) { - SDLJoystick joystick = getJoystick(event.getDeviceId()); - if (joystick != null) { - for (int i = 0; i < joystick.axes.size(); i++) { - InputDevice.MotionRange range = joystick.axes.get(i); - /* Normalize the value to -1...1 */ - float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f; - SDLControllerManager.onNativeJoy(joystick.device_id, i, value); - } - for (int i = 0; i < joystick.hats.size() / 2; i++) { - int hatX = Math.round(event.getAxisValue(joystick.hats.get(2 * i).getAxis(), actionPointerIndex)); - int hatY = Math.round(event.getAxisValue(joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex)); - SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY); - } + int actionPointerIndex = event.getActionIndex(); + int action = event.getActionMasked(); + if (action == MotionEvent.ACTION_MOVE) { + SDLJoystick joystick = getJoystick(event.getDeviceId()); + if (joystick != null) { + for (int i = 0; i < joystick.axes.size(); i++) { + InputDevice.MotionRange range = joystick.axes.get(i); + /* Normalize the value to -1...1 */ + float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f; + SDLControllerManager.onNativeJoy(joystick.device_id, i, value); + } + for (int i = 0; i < joystick.hats.size() / 2; i++) { + int hatX = Math.round(event.getAxisValue(joystick.hats.get(2 * i).getAxis(), actionPointerIndex)); + int hatY = Math.round(event.getAxisValue(joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex)); + SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY); } } } @@ -562,8 +560,6 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener { switch ( event.getSource() ) { case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); case InputDevice.SOURCE_MOUSE: @@ -693,8 +689,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 { switch ( event.getSource() ) { case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); case InputDevice.SOURCE_MOUSE: From 7ef76d0f1c98584d617e5c438560c0723a78f05c Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 23:32:02 -0500 Subject: [PATCH 32/36] what? --- src/gui/chanOsc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/chanOsc.cpp b/src/gui/chanOsc.cpp index 24c25f4bd..7b0f8a027 100644 --- a/src/gui/chanOsc.cpp +++ b/src/gui/chanOsc.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _USE_MATH_DEFINES #include "gui.h" #include "../ta-log.h" #include "imgui.h" From 4566068afd55f0803cfbd9604b3499c26e8b8778 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 23:38:38 -0500 Subject: [PATCH 33/36] SADFGLKJHASHDJLFK --- src/gui/editControls.cpp | 1 + src/gui/insEdit.cpp | 1 + src/gui/pattern.cpp | 1 - src/gui/sampleEdit.cpp | 2 ++ 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/editControls.cpp b/src/gui/editControls.cpp index b10c85ea3..f019f766b 100644 --- a/src/gui/editControls.cpp +++ b/src/gui/editControls.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _USE_MATH_DEFINES #include "gui.h" #include "IconsFontAwesome4.h" #include diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 7e48b2460..8eb841c7f 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _USE_MATH_DEFINES #include "gui.h" #include "imgui_internal.h" #include "../engine/macroInt.h" diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index 2c611d46d..d14902eef 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -18,7 +18,6 @@ */ // for suck's fake Clang extension! -#include #define _USE_MATH_DEFINES #include "gui.h" #include "../ta-log.h" diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index beca31025..2f80a04f8 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -16,6 +16,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#define _USE_MATH_DEFINES #include "gui.h" #include #include From f43363c5384448a97190de2cb41d939e6f4d6fe5 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Wed, 14 Dec 2022 23:55:29 -0500 Subject: [PATCH 34/36] allocate IDs for K00 and GA20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and ins ID for Pokémon Mini --- papers/format.md | 2 ++ papers/newIns.md | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/papers/format.md b/papers/format.md index 685e1aefd..d30c48b52 100644 --- a/papers/format.md +++ b/papers/format.md @@ -271,6 +271,8 @@ size | description | - 0xc3: OPN CSM - 10 channels | - 0xc4: PC-98 CSM - 20 channels | - 0xc5: YM2610B CSM - 20 channels + | - 0xc6: K007232 - 2 channels + | - 0xc7: GA20 - 4 channels | - 0xde: YM2610B extended - 19 channels | - 0xe0: QSound - 19 channels | - 0xfc: Pong - 1 channel diff --git a/papers/newIns.md b/papers/newIns.md index dbc1e4f2d..548edbdeb 100644 --- a/papers/newIns.md +++ b/papers/newIns.md @@ -65,6 +65,57 @@ size | description ??? | data... ``` +the following instrument types are available: + +- 0: SN76489 +- 1: FM (OPN) +- 2: Game Boy +- 3: C64 +- 4: Amiga/sample +- 5: PC Engine +- 6: AY-3-8910 +- 7: AY8930 +- 8: TIA +- 9: SAA1099 +- 10: VIC +- 11: PET +- 12: VRC6 +- 13: OPLL +- 14: OPL +- 15: FDS +- 16: Virtual Boy +- 17: Namco 163 +- 18: SCC +- 19: OPZ +- 20: POKEY +- 21: PC Speaker +- 22: WonderSwan +- 23: Lynx +- 24: VERA +- 25: X1-010 +- 26: VRC6 (saw) +- 27: ES5506 +- 28: MultiPCM +- 29: SNES +- 30: Sound Unit +- 31: Namco WSG +- 32: OPL (drums) +- 33: FM (OPM) +- 34: NES +- 35: MSM6258 +- 36: MSM6295 +- 37: ADPCM-A +- 38: ADPCM-B +- 39: SegaPCM +- 40: QSound +- 41: YMZ280B +- 42: RF5C68 +- 43: MSM5232 +- 44: T6W28 +- 45: K007232 +- 46: GA20 +- 47: Pokémon Mini + the following feature codes are recognized: - `NA`: instrument name From b619580b4bca0b0f9e2e72b24163a75092ca4f44 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 15 Dec 2022 00:47:46 -0500 Subject: [PATCH 35/36] =?UTF-8?q?add=20ins=20type=20for=20Pok=C3=A9mon=20M?= =?UTF-8?q?ini=20and=20GA20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/engine/instrument.cpp | 8 +++++++- src/engine/instrument.h | 2 ++ src/engine/song.h | 1 + src/engine/sysDef.cpp | 12 +++++++++++- src/gui/dataList.cpp | 8 ++++++++ src/gui/gui.h | 2 ++ src/gui/guiConst.cpp | 4 ++++ src/gui/insEdit.cpp | 6 +++++- src/gui/settings.cpp | 3 +++ 9 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index 76168173f..384e0b780 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -915,7 +915,13 @@ void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song) { featureSM=true; featureSL=true; break; - + case DIV_INS_GA20: + featureSM=true; + featureSL=true; + break; + case DIV_INS_POKEMINI: + break; + case DIV_INS_MAX: break; case DIV_INS_NULL: diff --git a/src/engine/instrument.h b/src/engine/instrument.h index a4c1effc8..65a81f8b6 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -76,6 +76,8 @@ enum DivInstrumentType: unsigned short { DIV_INS_MSM5232=43, DIV_INS_T6W28=44, DIV_INS_K007232=45, + DIV_INS_GA20=46, + DIV_INS_POKEMINI=47, DIV_INS_MAX, DIV_INS_NULL }; diff --git a/src/engine/song.h b/src/engine/song.h index 44cdd9790..e1a1607db 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -116,6 +116,7 @@ enum DivSystem { DIV_SYSTEM_MSM5232, DIV_SYSTEM_T6W28, DIV_SYSTEM_K007232, + DIV_SYSTEM_GA20, DIV_SYSTEM_PCM_DAC, DIV_SYSTEM_PONG, DIV_SYSTEM_DUMMY diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index d713a65b4..0b30b7eb7 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1174,7 +1174,7 @@ void DivEngine::registerSystems() { {"Square"}, {"SQ"}, {DIV_CH_PULSE}, - {DIV_INS_BEEPER} + {DIV_INS_POKEMINI} ); sysDefs[DIV_SYSTEM_SEGAPCM]=new DivSysDef( @@ -1703,6 +1703,16 @@ void DivEngine::registerSystems() { {DIV_INS_AMIGA, DIV_INS_AMIGA} ); + sysDefs[DIV_SYSTEM_GA20]=new DivSysDef( + "Irem GA20", NULL, 0xc7, 0, 4, false, true, 0x171, false, 1U<type==DIV_INS_QSOUND) { volMax=16383; } + if (ins->type==DIV_INS_POKEMINI) { + volMax=2; + } const char* dutyLabel="Duty/Noise"; int dutyMin=0; @@ -4982,7 +4985,7 @@ void FurnaceGUI::drawInsEdit() { dutyLabel="Group Ctrl"; dutyMax=5; } - if (ins->type==DIV_INS_BEEPER) { + if (ins->type==DIV_INS_BEEPER || ins->type==DIV_INS_POKEMINI) { dutyLabel="Pulse Width"; dutyMax=255; } @@ -5079,6 +5082,7 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_MSM6295) waveMax=0; if (ins->type==DIV_INS_SEGAPCM) waveMax=0; if (ins->type==DIV_INS_K007232) waveMax=0; + if (ins->type==DIV_INS_POKEMINI) waveMax=0; if (ins->type==DIV_INS_SU) waveMax=7; if (ins->type==DIV_INS_PET) { waveMax=8; diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index db8906209..d40e4dac7 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1787,7 +1787,10 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_INSTR_QSOUND,"QSound"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_YMZ280B,"YMZ280B"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_RF5C68,"RF5C68"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_MSM5232,"MSM5232"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_K007232,"K007232"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_GA20,"GA20"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_POKEMINI,"Pokémon Mini"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_UNKNOWN,"Other/Unknown"); ImGui::TreePop(); } From 301c473413f7d47a5b439224feb7c57fdb9bd390 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 15 Dec 2022 00:48:11 -0500 Subject: [PATCH 36/36] Square -> Pulse --- src/engine/sysDef.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 0b30b7eb7..0cec489d6 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1171,8 +1171,8 @@ void DivEngine::registerSystems() { sysDefs[DIV_SYSTEM_POKEMINI]=new DivSysDef( "Pokémon Mini", NULL, 0x99, 0, 1, false, true, 0, false, 0, "this one is like PC Speaker but has duty cycles.", - {"Square"}, - {"SQ"}, + {"Pulse"}, + {"P"}, {DIV_CH_PULSE}, {DIV_INS_POKEMINI} );