@@ -17,6 +17,7 @@ using namespace Ee;
1717#define STATE_LAST_RESULT (" lastResult" )
1818#define STATE_WAIT_THREADID (" waitThreadId" )
1919#define STATE_WAIT_VBLANK_COUNT (" waitVBlankCount" )
20+ #define STATE_COMMAND_DELAY_VBLANK_COUNT (" commandDelayVblankCount" )
2021
2122#define MC_PORT 0
2223
@@ -55,6 +56,7 @@ void CLibMc2::SaveState(Framework::CZipArchiveWriter& archive)
5556 registerFile->SetRegister32 (STATE_LAST_RESULT, m_lastResult);
5657 registerFile->SetRegister32 (STATE_WAIT_THREADID, m_waitThreadId);
5758 registerFile->SetRegister32 (STATE_WAIT_VBLANK_COUNT, m_waitVBlankCount);
59+ registerFile->SetRegister32 (STATE_COMMAND_DELAY_VBLANK_COUNT, m_commandDelayVBlankCount);
5860 archive.InsertFile (std::move (registerFile));
5961}
6062
@@ -65,6 +67,7 @@ void CLibMc2::LoadState(Framework::CZipArchiveReader& archive)
6567 m_lastResult = registerFile.GetRegister32 (STATE_LAST_RESULT);
6668 m_waitThreadId = registerFile.GetRegister32 (STATE_WAIT_THREADID);
6769 m_waitVBlankCount = registerFile.GetRegister32 (STATE_WAIT_VBLANK_COUNT);
70+ m_commandDelayVBlankCount = registerFile.GetRegister32 (STATE_COMMAND_DELAY_VBLANK_COUNT);
6871}
6972
7073uint32 CLibMc2::AnalyzeFunction (MODULE_FUNCTIONS& moduleFunctions, uint32 startAddress, int16 stackAlloc)
@@ -408,6 +411,10 @@ void CLibMc2::NotifyVBlankStart()
408411 m_waitThreadId = WAIT_THREAD_ID_EMPTY;
409412 }
410413 }
414+ if (m_commandDelayVBlankCount != 0 )
415+ {
416+ m_commandDelayVBlankCount--;
417+ }
411418}
412419
413420static void CopyDirParamTime (CLibMc2::DIRPARAM::TIME* dst, const Iop::CMcServ::ENTRY::TIME* src)
@@ -444,20 +451,34 @@ void CLibMc2::CheckAsync(CMIPS& context)
444451 // Returns -1 if no function was executing
445452 uint32 result = (m_lastCmd != 0 ) ? 1 : -1 ;
446453
447- // Don't report last cmd result if we didn't execute a command
448- uint32 lastCmdResult = (m_lastCmd != 0 ) ? m_lastResult : 0 ;
454+ if (mode == 0 )
455+ {
456+ // If we're in sync mode, consider the command delay complete.
457+ m_commandDelayVBlankCount = 0 ;
458+ }
449459
450- if (cmdPtr ! = 0 )
460+ if (m_commandDelayVBlankCount = = 0 )
451461 {
452- *reinterpret_cast <uint32*>(m_eeBios.GetStructPtr (cmdPtr)) = m_lastCmd;
462+ // Don't report last cmd result if we didn't execute a command
463+ uint32 lastCmdResult = (m_lastCmd != 0 ) ? m_lastResult : 0 ;
464+
465+ if (cmdPtr != 0 )
466+ {
467+ *reinterpret_cast <uint32*>(m_eeBios.GetStructPtr (cmdPtr)) = m_lastCmd;
468+ }
469+ if (resultPtr != 0 )
470+ {
471+ *reinterpret_cast <uint32*>(m_eeBios.GetStructPtr (resultPtr)) = lastCmdResult;
472+ }
473+
474+ m_lastCmd = 0 ;
453475 }
454- if (resultPtr != 0 )
476+ else
455477 {
456- *reinterpret_cast <uint32*>(m_eeBios.GetStructPtr (resultPtr)) = lastCmdResult;
478+ // Report that command is still running
479+ result = 0 ;
457480 }
458481
459- m_lastCmd = 0 ;
460-
461482 context.m_State .nGPR [CMIPS::V0].nD0 = static_cast <int32>(result);
462483
463484 // Mode:
@@ -487,6 +508,9 @@ int32 CLibMc2::GetInfoAsync(uint32 socketId, uint32 infoPtr)
487508 m_lastResult = MC2_RESULT_OK;
488509 m_lastCmd = SYSCALL_MC2_GETINFO_ASYNC & 0xFF ;
489510
511+ // Arbitrary delay to fix some games (Princess Lover! series)
512+ m_commandDelayVBlankCount = 3 ;
513+
490514 return 0 ;
491515}
492516
0 commit comments