From 39613a95a80db27d262ad8ed4b75858c78aeed83 Mon Sep 17 00:00:00 2001 From: nitsuja Date: Mon, 2 Jan 2012 02:20:22 -0800 Subject: [PATCH] initialize the uninitialized --- Source/Core/Common/Src/VideoBackendBase.h | 4 +++ Source/Core/Core/Src/Core.cpp | 2 ++ Source/Core/Core/Src/CoreTiming.cpp | 1 + Source/Core/Core/Src/HW/AudioInterface.cpp | 6 ++++ Source/Core/Core/Src/HW/GPFifo.cpp | 1 + Source/Core/Core/Src/HW/HW.cpp | 1 + Source/Core/Core/Src/HW/SI.cpp | 6 ++-- Source/Core/Core/Src/HW/SystemTimers.cpp | 13 +++++--- Source/Core/Core/Src/HW/SystemTimers.h | 1 + Source/Core/Core/Src/HW/VideoInterface.cpp | 26 ++++++++++++++++ Source/Core/Core/Src/Movie.cpp | 30 ++++++++++++++++++- Source/Core/Core/Src/Movie.h | 1 + Source/Core/Core/Src/PowerPC/PPCCache.cpp | 10 +++++++ Source/Core/Core/Src/PowerPC/PPCCache.h | 3 +- Source/Core/Core/Src/PowerPC/PowerPC.cpp | 13 +++++++- .../Core/VideoCommon/Src/CommandProcessor.cpp | 7 +++++ Source/Core/VideoCommon/Src/MainBase.cpp | 12 ++++++++ Source/Core/VideoCommon/Src/PixelEngine.cpp | 10 +++++++ .../VideoCommon/Src/VertexShaderManager.cpp | 6 ++++ Source/Core/VideoCommon/Src/VideoState.cpp | 11 +++++++ Source/Core/VideoCommon/Src/VideoState.h | 1 + Source/Plugins/Plugin_VideoDX11/Src/main.cpp | 1 + Source/Plugins/Plugin_VideoDX9/Src/main.cpp | 1 + Source/Plugins/Plugin_VideoOGL/Src/main.cpp | 1 + 24 files changed, 157 insertions(+), 11 deletions(-) diff --git a/Source/Core/Common/Src/VideoBackendBase.h b/Source/Core/Common/Src/VideoBackendBase.h index 667a3d3a32..28c8f23246 100644 --- a/Source/Core/Common/Src/VideoBackendBase.h +++ b/Source/Core/Common/Src/VideoBackendBase.h @@ -140,6 +140,7 @@ class VideoBackendHardware : public VideoBackend { void DoState(PointerWrap &p); void RunLoop(bool enable); + bool Initialize(void *&) { InitializeShared(); return true; } void EmuStateChange(EMUSTATE_CHANGE); @@ -165,6 +166,9 @@ class VideoBackendHardware : public VideoBackend readFn16 Video_PERead16(); writeFn16 Video_PEWrite16(); writeFn32 Video_PEWrite32(); + +protected: + void InitializeShared(); }; #endif diff --git a/Source/Core/Core/Src/Core.cpp b/Source/Core/Core/Src/Core.cpp index c1f9cf4415..bd4267c074 100644 --- a/Source/Core/Core/Src/Core.cpp +++ b/Source/Core/Core/Src/Core.cpp @@ -346,6 +346,8 @@ void EmuThread() DisplayMessage(cpu_info.Summarize(), 8000); DisplayMessage(_CoreParameter.m_strFilename, 3000); + Movie::Init(); + HW::Init(); if (!g_video_backend->Initialize(g_pWindowHandle)) diff --git a/Source/Core/Core/Src/CoreTiming.cpp b/Source/Core/Core/Src/CoreTiming.cpp index 979add358b..235593d679 100644 --- a/Source/Core/Core/Src/CoreTiming.cpp +++ b/Source/Core/Core/Src/CoreTiming.cpp @@ -133,6 +133,7 @@ void Init() void Shutdown() { + MoveEvents(); ClearPendingEvents(); UnregisterAllEvents(); diff --git a/Source/Core/Core/Src/HW/AudioInterface.cpp b/Source/Core/Core/Src/HW/AudioInterface.cpp index 4f1fbb920f..40b0c620b3 100644 --- a/Source/Core/Core/Src/HW/AudioInterface.cpp +++ b/Source/Core/Core/Src/HW/AudioInterface.cpp @@ -153,6 +153,12 @@ void Init() m_Volume.hex = 0; m_SampleCounter = 0; m_InterruptTiming = 0; + + g_LastCPUTime = 0; + g_CPUCyclesPerSample = 0xFFFFFFFFFFFULL; + + g_AISSampleRate = 48000; + g_AIDSampleRate = 32000; } void Shutdown() diff --git a/Source/Core/Core/Src/HW/GPFifo.cpp b/Source/Core/Core/Src/HW/GPFifo.cpp index 486c757587..4d72317e0d 100644 --- a/Source/Core/Core/Src/HW/GPFifo.cpp +++ b/Source/Core/Core/Src/HW/GPFifo.cpp @@ -54,6 +54,7 @@ void DoState(PointerWrap &p) void Init() { ResetGatherPipe(); + memset(m_gatherPipe, 0, sizeof(m_gatherPipe)); } bool IsEmpty() diff --git a/Source/Core/Core/Src/HW/HW.cpp b/Source/Core/Core/Src/HW/HW.cpp index ad5ecc404a..0ec08b7d97 100644 --- a/Source/Core/Core/Src/HW/HW.cpp +++ b/Source/Core/Core/Src/HW/HW.cpp @@ -43,6 +43,7 @@ namespace HW void Init() { CoreTiming::Init(); + SystemTimers::PreInit(); State::Init(); diff --git a/Source/Core/Core/Src/HW/SI.cpp b/Source/Core/Core/Src/HW/SI.cpp index cd80c14daf..09697f4965 100644 --- a/Source/Core/Core/Src/HW/SI.cpp +++ b/Source/Core/Core/Src/HW/SI.cpp @@ -246,10 +246,8 @@ void Init() g_Channel[i].m_InHi.Hex = 0; g_Channel[i].m_InLo.Hex = 0; - if (Movie::IsUsingPad(i)) - AddDevice(SIDEVICE_GC_CONTROLLER, i); - else if (Movie::IsRecordingInput() || Movie::IsPlayingInput()) - AddDevice(SIDEVICE_NONE, i); + if (Movie::IsRecordingInput() || Movie::IsPlayingInput()) + AddDevice(Movie::IsUsingPad(i) ? SIDEVICE_GC_CONTROLLER : SIDEVICE_NONE, i); else AddDevice(SConfig::GetInstance().m_SIDevice[i], i); } diff --git a/Source/Core/Core/Src/HW/SystemTimers.cpp b/Source/Core/Core/Src/HW/SystemTimers.cpp index bfc2b61af6..b9f9fe0107 100644 --- a/Source/Core/Core/Src/HW/SystemTimers.cpp +++ b/Source/Core/Core/Src/HW/SystemTimers.cpp @@ -231,12 +231,19 @@ void PatchEngineCallback(u64 userdata, int cyclesLate) CoreTiming::ScheduleEvent(VideoInterface::GetTicksPerFrame() - cyclesLate, et_PatchEngine); } +// split from Init to break a circular dependency between VideoInterface::Init and SystemTimers::Init +void PreInit() +{ + if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) + CPU_CORE_CLOCK = 729000000u; + else + CPU_CORE_CLOCK = 486000000u; +} + void Init() { if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii) { - CPU_CORE_CLOCK = 729000000u; - if (!DSP::GetDSPEmulator()->IsLLE()) DSP_PERIOD = (int)(GetTicksPerSecond() * 0.003f); @@ -253,8 +260,6 @@ void Init() } else { - CPU_CORE_CLOCK = 486000000u; - if (!DSP::GetDSPEmulator()->IsLLE()) DSP_PERIOD = (int)(GetTicksPerSecond() * 0.005f); } diff --git a/Source/Core/Core/Src/HW/SystemTimers.h b/Source/Core/Core/Src/HW/SystemTimers.h index ec8e425907..629593bc1d 100644 --- a/Source/Core/Core/Src/HW/SystemTimers.h +++ b/Source/Core/Core/Src/HW/SystemTimers.h @@ -24,6 +24,7 @@ namespace SystemTimers { u32 GetTicksPerSecond(); +void PreInit(); void Init(); void Shutdown(); diff --git a/Source/Core/Core/Src/HW/VideoInterface.cpp b/Source/Core/Core/Src/HW/VideoInterface.cpp index 40b95f53f9..677f30921f 100644 --- a/Source/Core/Core/Src/HW/VideoInterface.cpp +++ b/Source/Core/Core/Src/HW/VideoInterface.cpp @@ -158,6 +158,29 @@ void Preset(bool _bNTSC) void Init() { + m_VerticalTimingRegister.Hex = 0; + m_DisplayControlRegister.Hex = 0; + m_HTiming0.Hex = 0; + m_HTiming1.Hex = 0; + m_VBlankTimingOdd.Hex = 0; + m_VBlankTimingEven.Hex = 0; + m_BurstBlankingOdd.Hex = 0; + m_BurstBlankingEven.Hex = 0; + m_XFBInfoTop.Hex = 0; + m_XFBInfoBottom.Hex = 0; + m_3DFBInfoTop.Hex = 0; + m_3DFBInfoBottom.Hex = 0; + m_VBeamPos = 0; + m_HBeamPos = 0; + m_HorizontalStepping.Hex = 0; + m_HorizontalScaling.Hex = 0; + m_UnkAARegister = 0; + m_Clock = 0; + m_DTVStatus.Hex = 0; + m_FBWidth = 0; + m_BorderHBlank.Hex = 0; + memset(&m_FilterCoefTables, 0, sizeof(m_FilterCoefTables)); + fields = Core::g_CoreStartupParameter.bVBeam ? 1 : 2; m_DTVStatus.ntsc_j = Core::g_CoreStartupParameter.bForceNTSCJ; @@ -165,6 +188,9 @@ void Init() for (int i = 0; i < 4; i++) m_InterruptRegister[i].Hex = 0; + for (int i = 0; i < 2; i++) + m_LatchRegister[i].Hex = 0; + m_DisplayControlRegister.Hex = 0; UpdateParameters(); } diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index b478af4743..9c2fb02d64 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -105,6 +105,34 @@ void FrameUpdate() g_bPolled = false; } +// called when game is booting up, even if no movie is active, +// but potentially after BeginRecordingInput or PlayInput has been called. +void Init() +{ + g_bPolled = false; + g_bFrameStep = false; + g_bFrameStop = false; + g_frameSkipCounter = g_framesToSkip; + memset(&g_padState, 0, sizeof(g_padState)); + for (int i = 0; i < 8; ++i) + g_InputDisplay[i].clear(); + + if (!IsPlayingInput() && !IsRecordingInput()) + { + g_bRecordingFromSaveState = false; + g_rerecords = 0; + g_numPads = 0; + g_currentByte = 0; + g_currentFrame = 0; + g_currentLagCount = 0; + g_currentInputCount = 0; + // we don't clear these things because otherwise we can't resume playback if we load a movie state later + //g_totalFrames = g_totalBytes = 0; + //delete tmpInput; + //tmpInput = NULL; + } +} + void InputUpdate() { g_currentInputCount++; @@ -813,7 +841,7 @@ bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, if (size != sizeInMovie) { - PanicAlertT("Fatal desync. Aborting playback. (Error in PlayWiimote: %u != %u, byte %d.)%s", sizeInMovie, size, g_currentByte, (g_numPads & 0xF)?" Try re-creating the recording with all GameCube controllers disabled.":""); + PanicAlertT("Fatal desync. Aborting playback. (Error in PlayWiimote: %u != %u, byte %u.)%s", (u32)sizeInMovie, (u32)size, (u32)g_currentByte, (g_numPads & 0xF)?" Try re-creating the recording with all GameCube controllers disabled (in Configure > Gamecube > Device Settings).":""); EndPlayInput(!g_bReadOnly); return false; } diff --git a/Source/Core/Core/Src/Movie.h b/Source/Core/Core/Src/Movie.h index 9e01c48df1..16d0ba4997 100644 --- a/Source/Core/Core/Src/Movie.h +++ b/Source/Core/Core/Src/Movie.h @@ -105,6 +105,7 @@ struct DTMHeader { void FrameUpdate(); void InputUpdate(); +void Init(); void SetPolledDevice(); diff --git a/Source/Core/Core/Src/PowerPC/PPCCache.cpp b/Source/Core/Core/Src/PowerPC/PPCCache.cpp index af40568813..704caa4a2c 100644 --- a/Source/Core/Core/Src/PowerPC/PPCCache.cpp +++ b/Source/Core/Core/Src/PowerPC/PPCCache.cpp @@ -80,6 +80,16 @@ namespace PowerPC jit->GetBlockCache()->ClearSafe(); } + void InstructionCache::Init() + { + memset(data, 0, sizeof(data)); + memset(tags, 0, sizeof(tags)); + memset(way_from_valid, 0, sizeof(way_from_valid)); + memset(way_from_plru, 0, sizeof(way_from_plru)); + + Reset(); + } + void InstructionCache::Invalidate(u32 addr) { if (!HID0.ICE) diff --git a/Source/Core/Core/Src/PowerPC/PPCCache.h b/Source/Core/Core/Src/PowerPC/PPCCache.h index c2e428946c..6d62720d43 100644 --- a/Source/Core/Core/Src/PowerPC/PPCCache.h +++ b/Source/Core/Core/Src/PowerPC/PPCCache.h @@ -50,9 +50,10 @@ namespace PowerPC #endif InstructionCache(); - void Reset(); u32 ReadInstruction(u32 addr); void Invalidate(u32 addr); + void Init(); + void Reset(); }; } diff --git a/Source/Core/Core/Src/PowerPC/PowerPC.cpp b/Source/Core/Core/Src/PowerPC/PowerPC.cpp index 7e5d9ba763..2ae520faab 100644 --- a/Source/Core/Core/Src/PowerPC/PowerPC.cpp +++ b/Source/Core/Core/Src/PowerPC/PowerPC.cpp @@ -154,6 +154,17 @@ void Init(int cpu_core) //but still - set any useful sse options here #endif + memset(ppcState.mojs, 0, sizeof(ppcState.mojs)); + memset(ppcState.sr, 0, sizeof(ppcState.sr)); + ppcState.DebugCount = 0; + ppcState.dtlb_last = 0; + ppcState.dtlb_last = 0; + memset(ppcState.dtlb_va, 0, sizeof(ppcState.dtlb_va)); + memset(ppcState.dtlb_pa, 0, sizeof(ppcState.dtlb_pa)); + ppcState.itlb_last = 0; + memset(ppcState.itlb_va, 0, sizeof(ppcState.itlb_va)); + memset(ppcState.itlb_pa, 0, sizeof(ppcState.itlb_pa)); + ResetRegisters(); PPCTables::InitTables(cpu_core); @@ -197,7 +208,7 @@ void Init(int cpu_core) } state = CPU_STEPPING; - ppcState.iCache.Reset(); + ppcState.iCache.Init(); } void Shutdown() diff --git a/Source/Core/VideoCommon/Src/CommandProcessor.cpp b/Source/Core/VideoCommon/Src/CommandProcessor.cpp index ad05a9797e..67c8f411fa 100644 --- a/Source/Core/VideoCommon/Src/CommandProcessor.cpp +++ b/Source/Core/VideoCommon/Src/CommandProcessor.cpp @@ -109,6 +109,8 @@ void Init() m_CPCtrlReg.Hex = 0; + m_CPClearReg.Hex = 0; + m_bboxleft = 0; m_bboxtop = 0; m_bboxright = 640; @@ -130,6 +132,11 @@ void Init() interruptFinishWaiting = false; interruptTokenWaiting = false; + bProcessFifoToLoWatermark = false; + bProcessFifoAllDistance = false; + isPossibleWaitingSetDrawDone = false; + OnOverflow = false; + et_UpdateInterrupts = CoreTiming::RegisterEvent("UpdateInterrupts", UpdateInterrupts_Wrapper); } diff --git a/Source/Core/VideoCommon/Src/MainBase.cpp b/Source/Core/VideoCommon/Src/MainBase.cpp index 1fc8b15bec..af21ebbb94 100644 --- a/Source/Core/VideoCommon/Src/MainBase.cpp +++ b/Source/Core/VideoCommon/Src/MainBase.cpp @@ -171,6 +171,18 @@ u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 static volatile u32 s_doStateRequested = false; +void VideoBackendHardware::InitializeShared() +{ + VideoCommon_Init(); + + s_swapRequested = 0; + s_efbAccessRequested = 0; + s_FifoShuttingDown = 0; + memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs)); + memset(&s_accessEFBArgs, 0, sizeof(s_accessEFBArgs)); + s_AccessEFBResult = 0; +} + static volatile struct { unsigned char **ptr; diff --git a/Source/Core/VideoCommon/Src/PixelEngine.cpp b/Source/Core/VideoCommon/Src/PixelEngine.cpp index 90f1546ebd..456e0fb535 100644 --- a/Source/Core/VideoCommon/Src/PixelEngine.cpp +++ b/Source/Core/VideoCommon/Src/PixelEngine.cpp @@ -155,6 +155,16 @@ void SetFinish_OnMainThread(u64 userdata, int cyclesLate); void Init() { m_Control.Hex = 0; + m_ZConf.Hex = 0; + m_AlphaConf.Hex = 0; + m_DstAlphaConf.Hex = 0; + m_AlphaModeConf.Hex = 0; + m_AlphaRead.Hex = 0; + + g_bSignalTokenInterrupt = false; + g_bSignalFinishInterrupt = false; + interruptSetToken = false; + interruptSetFinish = false; et_SetTokenOnMainThread = CoreTiming::RegisterEvent("SetToken", SetToken_OnMainThread); et_SetFinishOnMainThread = CoreTiming::RegisterEvent("SetFinish", SetFinish_OnMainThread); diff --git a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp index a18829fde2..d7d25c5c85 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderManager.cpp @@ -150,6 +150,12 @@ void VertexShaderManager::Init() memset(&xfregs, 0, sizeof(xfregs)); memset(xfmem, 0, sizeof(xfmem)); ResetView(); + + // TODO: should these go inside ResetView()? + Matrix44::LoadIdentity(s_viewportCorrection); + memset(g_fProjectionMatrix, 0, sizeof(g_fProjectionMatrix)); + for (int i = 0; i < 4; ++i) + g_fProjectionMatrix[i*5] = 1.0f; } void VertexShaderManager::Shutdown() diff --git a/Source/Core/VideoCommon/Src/VideoState.cpp b/Source/Core/VideoCommon/Src/VideoState.cpp index 1a23410fcc..b1c1ed0889 100644 --- a/Source/Core/VideoCommon/Src/VideoState.cpp +++ b/Source/Core/VideoCommon/Src/VideoState.cpp @@ -60,3 +60,14 @@ void VideoCommon_RunLoop(bool enable) { EmulatorState(enable); } + +void VideoCommon_Init() +{ + memset(arraybases, 0, sizeof(arraybases)); + memset(arraystrides, 0, sizeof(arraystrides)); + memset(&MatrixIndexA, 0, sizeof(MatrixIndexA)); + memset(&MatrixIndexB, 0, sizeof(MatrixIndexB)); + memset(&g_VtxDesc, 0, sizeof(g_VtxDesc)); + memset(g_VtxAttr, 0, sizeof(g_VtxAttr)); + memset(texMem, 0, TMEM_SIZE); +} diff --git a/Source/Core/VideoCommon/Src/VideoState.h b/Source/Core/VideoCommon/Src/VideoState.h index b29cf17257..e596d9ad05 100644 --- a/Source/Core/VideoCommon/Src/VideoState.h +++ b/Source/Core/VideoCommon/Src/VideoState.h @@ -23,5 +23,6 @@ void VideoCommon_DoState(PointerWrap &p); void VideoCommon_RunLoop(bool enable); +void VideoCommon_Init(); #endif // _VIDEOSTATE_H diff --git a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp index f6fe1127a3..ba3a67108b 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/main.cpp @@ -150,6 +150,7 @@ void VideoBackend::ShowConfig(void *_hParent) bool VideoBackend::Initialize(void *&window_handle) { + InitializeShared(); InitBackendInfo(); frameCount = 0; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp index 727fa73a00..6c52219f97 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/main.cpp @@ -132,6 +132,7 @@ void VideoBackend::ShowConfig(void* parent) bool VideoBackend::Initialize(void *&window_handle) { + InitializeShared(); InitBackendInfo(); frameCount = 0; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp index a25f9cd839..251512fe6b 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/main.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/main.cpp @@ -155,6 +155,7 @@ void VideoBackend::ShowConfig(void *_hParent) bool VideoBackend::Initialize(void *&window_handle) { + InitializeShared(); InitBackendInfo(); frameCount = 0;