From ffa0727bf61bddc5ca07d219862bd63a04d9fe6b Mon Sep 17 00:00:00 2001 From: Laurens Holst Date: Mon, 2 May 2022 19:38:17 +0200 Subject: [PATCH] AY8930: Fix VGM output. It was generating writes to register addresses > 15. --- src/engine/platform/ay8930.cpp | 29 ++++++++++++++++++----------- src/engine/platform/ay8930.h | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/engine/platform/ay8930.cpp b/src/engine/platform/ay8930.cpp index 13308698c..5b823606b 100644 --- a/src/engine/platform/ay8930.cpp +++ b/src/engine/platform/ay8930.cpp @@ -25,7 +25,7 @@ #include #define rWrite(a,v) if (!skipRegisterWrites) {pendingWrites[a]=v;} -#define immWrite(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} } +#define immWrite2(a,v) if (!skipRegisterWrites) {writes.emplace(a,v); if (dumpWrites) {addWrite(a,v);} } #define CHIP_DIVIDER 8 @@ -61,6 +61,18 @@ const char* regCheatSheetAY8930[]={ NULL }; +void DivPlatformAY8930::immWrite(unsigned char a, unsigned char v) { + if ((int)bank!=(a>>4)) { + bank=a>>4; + immWrite2(0x0d, 0xa0|(bank<<4)|ayEnvMode[0]); + } + if (a==0x0d) { + immWrite2(0x0d,0xa0|(bank<<4)|(v&15)); + } else { + immWrite2(a&15,v); + } +} + const char** DivPlatformAY8930::getRegisterSheet() { return regCheatSheetAY8930; } @@ -123,18 +135,13 @@ void DivPlatformAY8930::acquire(short* bufL, short* bufR, size_t start, size_t l } while (!writes.empty()) { QueuedWrite w=writes.front(); - if ((int)bank!=(w.addr>>4)) { - bank=w.addr>>4; - ay->address_w(0x0d); - ay->data_w(0xa0|(bank<<4)|ayEnvMode[0]); - } - ay->address_w(w.addr&15); - if (w.addr==0x0d) { - ay->data_w(0xa0|(bank<<4)|(w.val&15)); + ay->address_w(w.addr); + ay->data_w(w.val); + if (w.addr!=0x0d && (regPool[0x0d]&0xf0)==0xb0) { + regPool[(w.addr&0x0f)|0x10]=w.val; } else { - ay->data_w(w.val); + regPool[w.addr&0x0f]=w.val; } - regPool[w.addr&0x1f]=w.val; writes.pop(); } ay->sound_stream_update(ayBuf,len); diff --git a/src/engine/platform/ay8930.h b/src/engine/platform/ay8930.h index ff992bb5e..5f477e123 100644 --- a/src/engine/platform/ay8930.h +++ b/src/engine/platform/ay8930.h @@ -73,6 +73,7 @@ class DivPlatformAY8930: public DivDispatch { size_t ayBufLen; void updateOutSel(bool immediate=false); + void immWrite(unsigned char a, unsigned char v); friend void putDispatchChan(void*,int,int);