From 4e881634308139403283456b7ada381f9e471916 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 13 Feb 2021 16:56:29 +0000 Subject: [PATCH] MB/6522: better reset support - only ACR,IFR,IER affected --- source/CPU.cpp | 1 - source/Mockingboard.cpp | 30 +++++++++++++++++++----------- source/Mockingboard.h | 2 +- source/Utilities.cpp | 4 ++-- source/Windows/AppleWin.cpp | 2 +- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/source/CPU.cpp b/source/CPU.cpp index 5578d0e5..a833c73c 100644 --- a/source/CPU.cpp +++ b/source/CPU.cpp @@ -701,7 +701,6 @@ void CpuIrqAssert(eIRQSRC Device) void CpuIrqDeassert(eIRQSRC Device) { - _ASSERT(g_bCritSectionValid); if (g_bCritSectionValid) EnterCriticalSection(&g_CriticalSection); g_bmIRQ &= ~(1<sy6522,0,sizeof(SY6522)); - pMB->sy6522.TIMER1_LATCH.w = 0xffff; // Some random value (but pick $ffff so it's deterministic) - // . NB. if it's too small (< ~$0007) then MB detection routines will fail! + if (powerCycle) + { + memset(&pMB->sy6522,0,sizeof(SY6522)); + pMB->sy6522.TIMER1_LATCH.w = 0xffff; // Some random value (but pick $ffff so it's deterministic) + // . NB. if it's too small (< ~$0007) then MB detection routines will fail! + } + + SY6522_Write(pMB->nAY8910Number, 0x0b, 0x00); // ACR = 0x00: T1 one-shot mode + SY6522_Write(pMB->nAY8910Number, 0x0d, 0x7f); // IFR = 0x7F: de-assert any IRQs + SY6522_Write(pMB->nAY8910Number, 0x0e, 0x7f); // IFE = 0x7F: disable all IRQs StopTimer1(pMB); StopTimer2(pMB); @@ -556,7 +565,6 @@ static void UpdateIFR(SY6522_AY8910* pMB, BYTE clr_ifr, BYTE set_ifr=0) { // Need critical section to avoid data-race: main thread & SSI263Thread can both access IFR // . NB. Loading a save-state just directly writes into 6522.IFR (which is fine) - _ASSERT(g_bCritSectionValid); if (g_bCritSectionValid) EnterCriticalSection(&g_CriticalSection); { pMB->sy6522.IFR &= ~clr_ifr; @@ -1726,7 +1734,7 @@ void MB_Initialize() g_bMBAvailable = MB_DSInit(); LogFileOutput("MB_Initialize: MB_DSInit(), g_bMBAvailable=%d\n", g_bMBAvailable); - MB_Reset(); + MB_Reset(true); LogFileOutput("MB_Initialize: MB_Reset()\n"); } @@ -1745,7 +1753,7 @@ static void MB_SetSoundcardType(SS_CARDTYPE NewSoundcardType); // . and voice will be demuted when dialog is closed void MB_InitializeForLoadingSnapshot() // GH#609 { - MB_Reset(); + MB_Reset(true); InitSoundcardType(); if (g_bDisableDirectSound || g_bDisableDirectSoundMockingboard) @@ -1823,14 +1831,14 @@ static void ResetState() // g_bPhasorEnable = false; } -void MB_Reset() // CTRL+RESET or power-cycle +void MB_Reset(const bool powerCycle) // CTRL+RESET or power-cycle { - if(!g_bDSAvailable) + if (!g_bDSAvailable) return; - for(int i=0; iCommReset(); PrintReset(); JoyReset(); - MB_Reset(); + MB_Reset(true); SpkrReset(); if (GetCardMgr().IsMouseCardInstalled()) GetCardMgr().GetMouseCard()->Reset(); @@ -583,7 +583,7 @@ void CtrlReset() KeybReset(); if (GetCardMgr().IsSSCInstalled()) GetCardMgr().GetSSC()->CommReset(); - MB_Reset(); + MB_Reset(false); if (GetCardMgr().IsMouseCardInstalled()) GetCardMgr().GetMouseCard()->Reset(); // Deassert any pending IRQs - GH#514 #ifdef USE_SPEECH_API diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index e96d4c46..3f39dbfa 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -647,7 +647,7 @@ int APIENTRY WinMain(HINSTANCE passinstance, HINSTANCE, LPSTR lpCmdLine, int) g_bRestartFullScreen = false; } - MB_Reset(); + MB_Reset(true); LogFileOutput("Main: MB_Reset()\n"); if (g_bRestart)