MB/6522: remove the legacy g_nMBTimerDevice variable.

Fix ASSERT from previous commit as SY6522.Reset() needs CriticalSection.
This commit is contained in:
tomcw 2022-02-12 18:42:58 +00:00
parent 8bbb85b1e8
commit 3fe06faf65
4 changed files with 33 additions and 25 deletions

View File

@ -35,11 +35,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "SynchronousEventManager.h"
#include "YamlHelper.h"
// TODO: remove these (just including for now to allow TU to compile)
extern UINT g_nMBTimerDevice;
static const UINT kTIMERDEVICE_INVALID = -1;
static const UINT kAY8910Number = 0; // needed?
void SY6522::Reset(const bool powerCycle)
{
if (powerCycle)
@ -49,6 +44,7 @@ void SY6522::Reset(const bool powerCycle)
// . NB. if it's too small (< ~$0007) then MB detection routines will fail!
}
CpuCreateCriticalSection(); // Reset() called by SY6522 global ctor, so explicitly create CPU's CriticalSection
Write(rACR, 0x00); // ACR = 0x00: T1 one-shot mode
Write(rIFR, 0x7f); // IFR = 0x7F: de-assert any IRQs
Write(rIER, 0x7f); // IER = 0x7F: disable all IRQs
@ -64,11 +60,6 @@ void SY6522::Reset(const bool powerCycle)
void SY6522::StartTimer1(void)
{
m_timer1Active = true;
if (m_regs.IER & IxR_TIMER1) // Using 6522 interrupt
g_nMBTimerDevice = kAY8910Number;
else if (m_regs.ACR & ACR_RM_FREERUNNING) // Polling 6522 IFR (GH#496)
g_nMBTimerDevice = kAY8910Number;
}
// The assumption was that timer1 was only active if IER.TIMER1=1
@ -79,13 +70,11 @@ void SY6522::StartTimer1_LoadStateV1(void)
return;
m_timer1Active = true;
g_nMBTimerDevice = kAY8910Number;
}
void SY6522::StopTimer1(void)
{
m_timer1Active = false;
g_nMBTimerDevice = kTIMERDEVICE_INVALID;
}
//-----------------------------------------------------------------------------
@ -94,8 +83,6 @@ void SY6522::StartTimer2(void)
{
m_timer2Active = true;
// NB. Can't mimic StartTimer1() as that would stomp on global state
// TODO: Switch to per-device state
}
void SY6522::StopTimer2(void)

View File

@ -633,6 +633,20 @@ DWORD CpuExecute(const DWORD uCycles, const bool bVideoUpdate)
//===========================================================================
// Called by:
// . CpuInitialize()
// . SY6522.Reset()
void CpuCreateCriticalSection(void)
{
if (!g_bCritSectionValid)
{
InitializeCriticalSection(&g_CriticalSection);
g_bCritSectionValid = true;
}
}
//===========================================================================
// Called from RepeatInitialization():
// 1) FrameCreateWindow() -> WM_CREATE
// - done to init g_CriticalSection
@ -645,11 +659,7 @@ void CpuInitialize(bool reset)
if (reset)
CpuReset();
if (!g_bCritSectionValid)
{
InitializeCriticalSection(&g_CriticalSection);
g_bCritSectionValid = true;
}
CpuCreateCriticalSection();
CpuIrqReset();
CpuNmiReset();

View File

@ -32,6 +32,7 @@ void CpuDestroy ();
void CpuCalcCycles(ULONG nExecutedCycles);
DWORD CpuExecute(const DWORD uCycles, const bool bVideoUpdate);
ULONG CpuGetCyclesThisVideoFrame(ULONG nExecutedCycles);
void CpuCreateCriticalSection(void);
void CpuInitialize(bool reset);
void CpuSetupBenchmark ();
void CpuIrqReset();

View File

@ -148,7 +148,6 @@ static SyncEvent* g_syncEvent[kNumSyncEvents];
// Timer vars
static const UINT kTIMERDEVICE_INVALID = -1;
UINT g_nMBTimerDevice = kTIMERDEVICE_INVALID; // SY6522 device# which is generating timer IRQ
static UINT64 g_uLastCumulativeCycles = 0;
static const DWORD SAMPLE_RATE = 44100; // Use a base freq so that DirectX (or sound h/w) doesn't have to up/down-sample
@ -188,6 +187,16 @@ static int MB_SyncEventCallback(int id, int cycles, ULONG uExecutedCycles);
//---------------------------------------------------------------------------
static bool IsAnyTimer1Active(void)
{
bool active = false;
for (UINT i = 0; i < NUM_AY8910; i++)
active |= g_MB[i].sy6522.IsTimer1Active();
return active;
}
//---------------------------------------------------------------------------
void MB_Get6522IrqDescription(std::string& desc)
{
for (UINT i=0; i<NUM_AY8910; i++)
@ -351,8 +360,8 @@ void MB_UpdateIRQ(void)
static UINT64 g_uLastMBUpdateCycle = 0;
// Called by:
// . MB_SyncEventCallback() on a TIMER1 (not TIMER2) underflow - when g_nMBTimerDevice == {0,1,2,3}
// . MB_PeriodicUpdate() - when g_nMBTimerDevice == kTIMERDEVICE_INVALID
// . MB_SyncEventCallback() on a TIMER1 (not TIMER2) underflow - when IsAnyTimer1Active() == true
// . MB_PeriodicUpdate() - when IsAnyTimer1Active() == false
static void MB_UpdateInt(void)
{
if (!MockingboardVoice.bActive)
@ -566,7 +575,7 @@ static void MB_Update(void)
#ifdef LOG_PERF_TIMINGS
extern UINT64 g_timeMB_NoTimer;
extern UINT64 g_timeMB_Timer;
PerfMarker perfMarker(g_nMBTimerDevice == kTIMERDEVICE_INVALID ? g_timeMB_NoTimer : g_timeMB_Timer);
PerfMarker perfMarker(!IsAnyTimer1Active() ? g_timeMB_NoTimer : g_timeMB_Timer);
#endif
MB_UpdateInt();
@ -762,7 +771,6 @@ void MB_Reset(const bool powerCycle) // CTRL+RESET or power-cycle
// Reset state
{
g_nMBTimerDevice = kTIMERDEVICE_INVALID;
MB_SetCumulativeCycles();
g_nMB_InActiveCycleCount = 0;
@ -1138,9 +1146,11 @@ void MB_PeriodicUpdate(UINT executedCycles)
for (UINT i=0; i<NUM_AY8910; i++)
g_MB[i].ssi263.PeriodicUpdate(executedCycles);
if (g_nMBTimerDevice != kTIMERDEVICE_INVALID)
if (IsAnyTimer1Active())
return;
// No 6522 TIMER1's are active, so periodically update AY8913's here...
const UINT kCyclesPerAudioFrame = 1000;
g_cyclesThisAudioFrame += executedCycles;
if (g_cyclesThisAudioFrame < kCyclesPerAudioFrame)