Skip to content

Commit 43d8cde

Browse files
committed
Add delay to GetInfoAsync.
Fixes Princess Lover series.
1 parent 088386a commit 43d8cde

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

Source/ee/Ee_LibMc2.cpp

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

7073
uint32 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

413420
static 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

Source/ee/Ee_LibMc2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,6 @@ namespace Ee
132132
uint32 m_lastResult = 0;
133133
uint32 m_waitThreadId = WAIT_THREAD_ID_EMPTY;
134134
uint32 m_waitVBlankCount = 0;
135+
uint32 m_commandDelayVBlankCount = 0;
135136
};
136137
}

0 commit comments

Comments
 (0)