diff --git a/Source/Core/Common/Src/Thread.h b/Source/Core/Common/Src/Thread.h index ba713ed64c..e711fcab5c 100644 --- a/Source/Core/Common/Src/Thread.h +++ b/Source/Core/Common/Src/Thread.h @@ -72,6 +72,13 @@ public: is_set = false; } + void Reset() + { + std::unique_lock lk(m_mutex); + // no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration + is_set = false; + } + private: class IsSet { 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/CPU.cpp b/Source/Core/Core/Src/HW/CPU.cpp index 69b5055c9f..0f461b0fc5 100644 --- a/Source/Core/Core/Src/HW/CPU.cpp +++ b/Source/Core/Core/Src/HW/CPU.cpp @@ -115,6 +115,7 @@ void CCPU::EnableStepping(const bool _bStepping) if (_bStepping) { PowerPC::Pause(); + m_StepEvent.Reset(); g_video_backend->EmuStateChange(EMUSTATE_CHANGE_PAUSE); DSP::GetDSPEmulator()->DSP_ClearAudioBuffer(true); } diff --git a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp index 85bfd2428e..144270e798 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceIPL.cpp @@ -25,6 +25,8 @@ #include "MemoryUtil.h" #include "FileUtil.h" #include "../Movie.h" +#include "../CoreTiming.h" +#include "SystemTimers.h" // We should provide an option to choose from the above, or figure out the checksum (the algo in yagcd seems wrong) // so that people can change default language. @@ -342,14 +344,23 @@ void CEXIIPL::TransferByte(u8& _uByte) u32 CEXIIPL::GetGCTime() { u64 ltime = 0; - const u32 cJanuary2000 = 0x386D4380; // Seconds between 1.1.1970 and 1.1.2000 + static const u32 cJanuary2000 = 0x386D4380; // Seconds between 1.1.1970 and 1.1.2000 - // hack in some netplay stuff - ltime = NetPlay_GetGCTime(); if (Movie::IsRecordingInput() || Movie::IsPlayingInput()) - ltime = 1234567890; // TODO: Should you be able to set a custom time in movies? - else if (0 == ltime) - ltime = Common::Timer::GetLocalTimeSinceJan1970(); + { + ltime = Movie::GetRecordingStartTime(); + + // let's keep time moving forward, regardless of what it starts at + ltime += CoreTiming::GetTicks() / SystemTimers::GetTicksPerSecond(); + } + else + { + // hack in some netplay stuff + ltime = NetPlay_GetGCTime(); + + if (0 == ltime) + ltime = Common::Timer::GetLocalTimeSinceJan1970(); + } return ((u32)ltime - cJanuary2000); 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/HW/Wiimote.cpp b/Source/Core/Core/Src/HW/Wiimote.cpp index 149c1db01e..30ab7af141 100644 --- a/Source/Core/Core/Src/HW/Wiimote.cpp +++ b/Source/Core/Core/Src/HW/Wiimote.cpp @@ -48,7 +48,8 @@ void Initialize(void* const hwnd) WiimoteReal::Initialize(); - if (Movie::IsPlayingInput()) // reload Wiimotes with our settings + // reload Wiimotes with our settings + if (Movie::IsPlayingInput() || Movie::IsRecordingInput()) Movie::ChangeWiiPads(); } diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp index 5afc5b522d..6f7f80ece7 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.cpp @@ -301,7 +301,7 @@ Wiimote::Wiimote( const unsigned int index ) m_options->settings.push_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false)); // TODO: This value should probably be re-read if SYSCONF gets changed - m_sensor_bar_on_top = (bool)SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR"); + m_sensor_bar_on_top = SConfig::GetInstance().m_SYSCONF->GetData("BT.BAR") != 0; // --- reset eeprom/register/values to default --- Reset(); @@ -318,7 +318,6 @@ std::string Wiimote::GetName() const bool Wiimote::Step() { const bool has_focus = HAS_FOCUS; - const bool is_sideways = m_options->settings[1]->value != 0; // TODO: change this a bit m_motion_plus_present = m_extension->settings[0]->value != 0; @@ -329,13 +328,10 @@ bool Wiimote::Step() m_rumble->controls[0]->control_ref->State(m_rumble_on); - // update buttons in status struct - m_status.buttons = 0; - if (has_focus) + // when a movie is active, this button status update is disabled (moved), because movies only record data reports. + if(!(Movie::IsPlayingInput() || Movie::IsRecordingInput())) { - m_buttons->GetState(&m_status.buttons, button_bitmasks); - m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks); - UDPTLayer::GetButtons(m_udp, &m_status.buttons); + UpdateButtonsStatus(has_focus); } // check if there is a read data request @@ -375,8 +371,27 @@ bool Wiimote::Step() return false; } +void Wiimote::UpdateButtonsStatus(bool has_focus) +{ + // update buttons in status struct + m_status.buttons = 0; + if (has_focus) + { + const bool is_sideways = m_options->settings[1]->value != 0; + m_buttons->GetState(&m_status.buttons, button_bitmasks); + m_dpad->GetState(&m_status.buttons, is_sideways ? dpad_sideways_bitmasks : dpad_bitmasks); + UDPTLayer::GetButtons(m_udp, &m_status.buttons); + } +} + void Wiimote::GetCoreData(u8* const data) { + // when a movie is active, the button update happens here instead of Wiimote::Step, to avoid potential desync issues. + if(Movie::IsPlayingInput() || Movie::IsRecordingInput()) + { + UpdateButtonsStatus(HAS_FOCUS); + } + *(wm_core*)data |= m_status.buttons; } @@ -639,7 +654,12 @@ void Wiimote::Update() const ReportFeatures& rptf = reporting_mode_features[m_reporting_mode - WM_REPORT_CORE]; rptf_size = rptf.size; - if (!Movie::IsPlayingInput() || !Movie::PlayWiimote(m_index, data, rptf, m_reg_ir.mode)) + if (Movie::IsPlayingInput() && Movie::PlayWiimote(m_index, data, rptf, m_reg_ir.mode)) + { + if (rptf.core) + m_status.buttons = *(wm_core*)(data + rptf.core); + } + else { data[0] = 0xA1; data[1] = m_reporting_mode; @@ -741,10 +761,10 @@ void Wiimote::Update() } } } - if (Movie::IsRecordingInput()) - { - Movie::RecordWiimote(m_index, data, rptf, m_reg_ir.mode); - } + } + if (Movie::IsRecordingInput()) + { + Movie::RecordWiimote(m_index, data, rptf, m_reg_ir.mode); } // don't send a data report if auto reporting is off diff --git a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.h index ecc86ad5b3..17a3a2adfc 100644 --- a/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/Src/HW/WiimoteEmu/WiimoteEmu.h @@ -113,6 +113,7 @@ protected: bool Step(); void HidOutputReport(const wm_report* const sr, const bool send_ack = true); void HandleExtensionSwap(); + void UpdateButtonsStatus(bool has_focus); void GetCoreData(u8* const data); void GetAccelData(u8* const data, u8* const buttons); diff --git a/Source/Core/Core/Src/Movie.cpp b/Source/Core/Core/Src/Movie.cpp index 07564c69a8..9c2fb02d64 100644 --- a/Source/Core/Core/Src/Movie.cpp +++ b/Source/Core/Core/Src/Movie.cpp @@ -29,6 +29,7 @@ #include "IPC_HLE/WII_IPC_HLE_Device_usb.h" #include "VideoBackendBase.h" #include "State.h" +#include "Timer.h" // large enough for just over 24 hours of single-player recording #define MAX_DTM_LENGTH (40 * 1024 * 1024) @@ -53,6 +54,7 @@ u64 g_currentByte = 0, g_totalBytes = 0; u64 g_currentFrame = 0, g_totalFrames = 0; // VI u64 g_currentLagCount = 0, g_totalLagCount = 0; // just stats u64 g_currentInputCount = 0, g_totalInputCount = 0; // just stats +u64 g_recordingStartTime; // seconds since 1970 that recording started bool g_bRecordingFromSaveState = false; bool g_bPolled = false; @@ -64,6 +66,7 @@ std::string g_InputDisplay[8]; ManipFunction mfunc = NULL; + std::string GetInputDisplay() { std::string inputDisplay = ""; @@ -102,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++; @@ -196,6 +227,11 @@ bool IsReadOnly() return g_bReadOnly; } +u64 GetRecordingStartTime() +{ + return g_recordingStartTime; +} + bool IsUsingPad(int controller) { return ((g_numPads & (1 << controller)) != 0); @@ -264,6 +300,7 @@ bool BeginRecordingInput(int controllers) g_currentFrame = g_totalFrames = 0; g_currentLagCount = g_totalLagCount = 0; g_currentInputCount = g_totalInputCount = 0; + g_recordingStartTime = Common::Timer::GetLocalTimeSinceJan1970(); g_rerecords = 0; g_playMode = MODE_RECORDING; @@ -532,6 +569,7 @@ bool PlayInput(const char *filename) g_totalFrames = tmpHeader.frameCount; g_totalLagCount = tmpHeader.lagCount; g_totalInputCount = tmpHeader.inputCount; + g_recordingStartTime = tmpHeader.recordingStartTime; g_currentFrame = 0; g_currentLagCount = 0; @@ -630,7 +668,7 @@ void LoadInput(const char *filename) } else if(g_currentByte > 0 && g_totalBytes > 0) { - // verify identical from movie start to thee save's current frame + // verify identical from movie start to the save's current frame u32 len = (u32)g_currentByte; u8* movInput = new u8[len]; t_record.ReadArray(movInput, (size_t)len); @@ -676,20 +714,6 @@ void LoadInput(const char *filename) g_rerecords = tmpHeader.numRerecords; - if(g_currentSaveVersion == 0) - { - // attempt support for old savestates with movies but without movie-related data in DoState. - // I'm just guessing here and the old logic was kind of broken anyway, so this probably doesn't work well. - g_totalFrames = tmpHeader.frameCount; - if(g_totalFrames < tmpHeader.deprecated_totalFrameCount) - g_totalFrames = tmpHeader.deprecated_totalFrameCount; - u64 frameStart = tmpHeader.deprecated_frameStart ? tmpHeader.deprecated_frameStart : tmpHeader.frameCount; - g_currentFrame = frameStart; - g_currentByte = frameStart * 8; - g_currentLagCount = tmpHeader.lagCount; - g_currentInputCount = tmpHeader.inputCount; - } - if (!afterEnd) { if (g_bReadOnly) @@ -817,7 +841,7 @@ bool PlayWiimote(int wiimote, u8 *data, const WiimoteEmu::ReportFeatures& rptf, if (size != sizeInMovie) { - PanicAlertT("Error in PlayWiimote. %u != %u, byte %d.\nSorry, Wii recording is temporarily broken.", sizeInMovie, size, g_currentByte); + 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; } @@ -880,6 +904,7 @@ void SaveRecording(const char *filename) header.lagCount = g_totalLagCount; header.inputCount = g_totalInputCount; header.numRerecords = g_rerecords; + header.recordingStartTime = g_recordingStartTime; // TODO header.uniqueID = 0; diff --git a/Source/Core/Core/Src/Movie.h b/Source/Core/Core/Src/Movie.h index 3df376270e..16d0ba4997 100644 --- a/Source/Core/Core/Src/Movie.h +++ b/Source/Core/Core/Src/Movie.h @@ -89,7 +89,7 @@ struct DTMHeader { u64 frameCount; // Number of frames in the recording u64 inputCount; // Number of input frames in recording u64 lagCount; // Number of lag frames in the recording - u64 uniqueID; // A Unique ID comprised of: md5(time + Game ID) + u64 uniqueID; // (not implemented) A Unique ID comprised of: md5(time + Game ID) u32 numRerecords; // Number of rerecords/'cuts' of this TAS u8 author[32]; // Author's name (encoded in UTF-8) @@ -97,17 +97,15 @@ struct DTMHeader { u8 audioEmulator[16]; // UTF-8 representation of the audio emulator u8 padBackend[16]; // UTF-8 representation of the input backend - // hack, data that was only used for savestates and would more properly be stored in the savestate itself - // the hack has been removed, but these remain defined and reserved here for legacy support purposes - u64 deprecated_frameStart; // NOT USED ANYMORE (use g_currentFrame) - u64 deprecated_totalFrameCount; // NOT USED ANYMORE (use g_totalFrames or header.frameCount) + u64 recordingStartTime; // seconds since 1970 that recording started (used for RTC) - u8 reserved[111]; // Make heading 256 bytes, just because we can + u8 reserved[119]; // Make heading 256 bytes, just because we can }; #pragma pack(pop) void FrameUpdate(); void InputUpdate(); +void Init(); void SetPolledDevice(); @@ -117,6 +115,7 @@ bool IsRecordingInputFromSaveState(); bool IsJustStartingRecordingInputFromSaveState(); bool IsPlayingInput(); bool IsReadOnly(); +u64 GetRecordingStartTime(); bool IsUsingPad(int controller); bool IsUsingWiimote(int wiimote); 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;