From 7fee9b6f0515afbdcfa012269eac79505fd3337f Mon Sep 17 00:00:00 2001 From: Natt Akuma Date: Sat, 22 Jun 2024 15:32:11 +0700 Subject: [PATCH] VERA: add r47 revision with 9-bit volume table --- src/engine/fileOps/fur.cpp | 9 +++++++++ src/engine/platform/sound/vera_psg.c | 27 +++++++++++++++++++++------ src/engine/platform/sound/vera_psg.h | 4 ++-- src/engine/platform/vera.cpp | 3 ++- src/gui/sysConf.cpp | 23 ++++++++++++++++++++++- 5 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/engine/fileOps/fur.cpp b/src/engine/fileOps/fur.cpp index 7a51166b6..9c65963c7 100644 --- a/src/engine/fileOps/fur.cpp +++ b/src/engine/fileOps/fur.cpp @@ -2083,6 +2083,15 @@ bool DivEngine::loadFur(unsigned char* file, size_t len, int variantID) { } } + // VERA old chip revision + if (ds.version<213) { + for (int i=0; i @@ -14,7 +18,15 @@ enum waveform { WF_NOISE, }; -static uint8_t volume_lut[64] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31, 33, 35, 37, 39, 42, 44, 47, 50, 52, 56, 59, 63}; +static uint16_t volume_lut[64] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8, 9, 9, 10, 11, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 31, 33, 35, 37, 39, 42, 44, 47, 50, 52, 56, 59, 63}; +static uint16_t volume_lut_47[64] = { + 0, 4, 8, 12, + 16, 17, 18, 20, 21, 22, 23, 25, 26, 28, 30, 31, + 33, 35, 37, 40, 42, 45, 47, 50, 53, 56, 60, 63, + 67, 71, 75, 80, 85, 90, 95, 101, 107, 113, 120, 127, + 135, 143, 151, 160, 170, 180, 191, 202, 214, 227, 241, 255, + 270, 286, 303, 321, 341, 361, 382, 405, 429, 455, 482, 511 +}; void psg_reset(struct VERA_PSG* psg) @@ -38,7 +50,7 @@ psg_writereg(struct VERA_PSG* psg, uint8_t reg, uint8_t val) case 2: { psg->channels[ch].right = (val & 0x80) != 0; psg->channels[ch].left = (val & 0x40) != 0; - psg->channels[ch].volume = volume_lut[val & 0x3F]; + psg->channels[ch].volume = ((psg->chipType < 1) ? volume_lut : volume_lut_47)[val & 0x3F]; break; } case 3: { @@ -65,8 +77,11 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right) struct VERAChannel *ch = &psg->channels[i]; unsigned new_phase = (ch->phase + ch->freq) & 0x1FFFF; + if ((psg->chipType >= 1) && (!ch->left && !ch->right)) { + new_phase = 0; + } if ((ch->phase & 0x10000) != (new_phase & 0x10000)) { - ch->noiseval = psg->noiseOut; + ch->noiseval = (psg->chipType < 1) ? psg->noiseOut : (psg->noiseState >> 1) & 0x3f; } ch->phase = new_phase; @@ -85,14 +100,14 @@ render(struct VERA_PSG* psg, int16_t *left, int16_t *right) int val = (int)sv * (int)ch->volume; if (ch->left) { - l += val; + l += (psg->chipType < 1) ? val : val >> 3; } if (ch->right) { - r += val; + r += (psg->chipType < 1) ? val : val >> 3; } if (ch->left || ch->right) { - ch->lastOut = val; + ch->lastOut = (psg->chipType < 1) ? val << 3 : val; } else { ch->lastOut = 0; } diff --git a/src/engine/platform/sound/vera_psg.h b/src/engine/platform/sound/vera_psg.h index 6a3f6828b..078317647 100644 --- a/src/engine/platform/sound/vera_psg.h +++ b/src/engine/platform/sound/vera_psg.h @@ -9,7 +9,7 @@ struct VERAChannel { uint16_t freq; - uint8_t volume; + uint16_t volume; bool left, right; uint8_t pw; uint8_t waveform; @@ -20,7 +20,7 @@ struct VERAChannel { }; struct VERA_PSG { - unsigned int noiseState, noiseOut; + unsigned int chipType, noiseState, noiseOut; struct VERAChannel channels[16]; }; diff --git a/src/engine/platform/vera.cpp b/src/engine/platform/vera.cpp index 2e6180a95..e4e78933e 100644 --- a/src/engine/platform/vera.cpp +++ b/src/engine/platform/vera.cpp @@ -119,7 +119,7 @@ void DivPlatformVERA::acquire(short** buf, size_t len) { pos++; for (int i=0; i<16; i++) { - oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut<<3; + oscBuf[i]->data[oscBuf[i]->needle++]=psg->channels[i].lastOut; } int pcmOut=(whyCallItBuf[2][i]+whyCallItBuf[3][i])>>1; if (pcmOut<-32768) pcmOut=-32768; @@ -532,6 +532,7 @@ void DivPlatformVERA::poke(std::vector& wlist) { } void DivPlatformVERA::setFlags(const DivConfig& flags) { + psg->chipType=flags.getInt("chipType",1); chipClock=25000000; CHECK_CUSTOM_CLOCK; rate=chipClock/512; diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 25ffc4940..e9f46f1a1 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -2428,12 +2428,33 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl } break; } + case DIV_SYSTEM_VERA: { + int chipType=flags.getInt("chipType",1); + + ImGui::Text(_("Chip revision:")); + ImGui::Indent(); + if (ImGui::RadioButton(_("V 0.3.1"),chipType==0)) { + chipType=0; + altered=true; + } + if (ImGui::RadioButton(_("V 47.0.0 (9-bit volume)"),chipType==1)) { + chipType=1; + altered=true; + } + ImGui::Unindent(); + + if (altered) { + e->lockSave([&]() { + flags.set("chipType",chipType); + }); + } + break; + } case DIV_SYSTEM_SWAN: case DIV_SYSTEM_BUBSYS_WSG: case DIV_SYSTEM_PET: case DIV_SYSTEM_GA20: case DIV_SYSTEM_PV1000: - case DIV_SYSTEM_VERA: case DIV_SYSTEM_C219: case DIV_SYSTEM_BIFURCATOR: case DIV_SYSTEM_POWERNOISE: