From 5d46298dcc32a036c5d4d3214325726f8b7fbfc9 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sun, 17 Jan 2021 19:51:25 +0000 Subject: [PATCH] Mockingboard: support AY-3-8913 read --- source/AY8910.cpp | 45 +++++++++++++++++++++++++++++++++++++++++ source/AY8910.h | 3 +++ source/Mockingboard.cpp | 1 + 3 files changed, 49 insertions(+) diff --git a/source/AY8910.cpp b/source/AY8910.cpp index 3a0f0716..fe8fa5d4 100644 --- a/source/AY8910.cpp +++ b/source/AY8910.cpp @@ -709,6 +709,47 @@ void CAY8910::sound_ay_overlay( void ) } } +BYTE CAY8910::sound_ay_read( int reg ) +{ + reg &= 15; + + BYTE val = 0; + bool got = false; + + if (ay_change_count) + { + for (int i=ay_change_count-1; i>=0; i--) + { + if (ay_change[i].reg == reg) + { + val = ay_change[i].val; // return the most recently written reg's value + got = true; + } + } + } + + if (!got) + val = sound_ay_registers[reg]; + + switch (reg & 15) + { + case 1: + case 3: + case 5: + case 13: + val &= 15; + break; + case 6: + case 8: + case 9: + case 10: + val &= 31; + break; + } + + return val; +} + // AppleWin:TC Holding down ScrollLock will result in lots of AY changes /ay_change_count/ // - since sound_ay_overlay() is called to consume them. @@ -1145,6 +1186,10 @@ bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& su static CAY8910 g_AY8910[MAX_8910]; static unsigned __int64 g_uLastCumulativeCycles = 0; +BYTE AYReadReg(int chip, int r) +{ + return g_AY8910[chip].sound_ay_read(r); +} void _AYWriteReg(int chip, int r, int v) { diff --git a/source/AY8910.h b/source/AY8910.h index 85b246b3..0dc272b1 100644 --- a/source/AY8910.h +++ b/source/AY8910.h @@ -2,6 +2,8 @@ #define MAX_8910 4 +BYTE AYReadReg(int chip, int r); // TC + //------------------------------------- // MAME interface @@ -40,6 +42,7 @@ public: void sound_ay_init( void ); void sound_init( const char *device ); + BYTE sound_ay_read( int reg ); // TC void sound_ay_write( int reg, int val, libspectrum_dword now ); void sound_ay_reset( void ); void sound_frame( void ); diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index 5c3dd19d..50caae1d 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -321,6 +321,7 @@ static void AY8910_Write(BYTE nDevice, BYTE /*nReg*/, BYTE nValue, BYTE nAYDevic break; case AY_READ: // 5: READ FROM PSG (need to set DDRA to input) + pMB->sy6522.ORA = AYReadReg(nDevice+2*nAYDevice, pMB->nAYCurrentRegister) & (pMB->sy6522.DDRA ^ 0xff); break; case AY_WRITE: // 6: WRITE TO PSG