2008-12-01 04:00:36 +00:00
|
|
|
#include "Iop_Vblank.h"
|
|
|
|
#include "IopBios.h"
|
2025-03-11 12:48:26 -04:00
|
|
|
#include "Log.h"
|
2008-12-01 04:00:36 +00:00
|
|
|
|
|
|
|
using namespace Iop;
|
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
#define LOG_NAME "iop_vblank"
|
2008-12-01 04:00:36 +00:00
|
|
|
|
2018-04-30 21:01:23 +01:00
|
|
|
#define FUNCTION_WAITVBLANKSTART "WaitVblankStart"
|
|
|
|
#define FUNCTION_WAITVBLANKEND "WaitVblankEnd"
|
|
|
|
#define FUNCTION_WAITVBLANK "WaitVblank"
|
2017-03-01 19:33:46 -05:00
|
|
|
#define FUNCTION_REGISTERVBLANKHANDLER "RegisterVblankHandler"
|
2020-04-22 19:46:46 +02:00
|
|
|
#define FUNCTION_RELEASEVBLANKHANDLER "ReleaseVblankHandler"
|
2008-12-01 04:00:36 +00:00
|
|
|
|
2017-03-01 19:33:46 -05:00
|
|
|
CVblank::CVblank(CIopBios& bios)
|
2018-04-30 21:01:23 +01:00
|
|
|
: m_bios(bios)
|
2008-12-01 04:00:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-06 21:37:50 +00:00
|
|
|
std::string CVblank::GetId() const
|
2008-12-01 04:00:36 +00:00
|
|
|
{
|
2017-03-01 19:33:46 -05:00
|
|
|
return "vblank";
|
2008-12-01 04:00:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-06 21:37:50 +00:00
|
|
|
std::string CVblank::GetFunctionName(unsigned int functionId) const
|
2008-12-01 04:00:36 +00:00
|
|
|
{
|
2017-03-01 19:33:46 -05:00
|
|
|
switch(functionId)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
return FUNCTION_WAITVBLANKSTART;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
return FUNCTION_WAITVBLANKEND;
|
|
|
|
break;
|
2017-03-04 23:41:09 -05:00
|
|
|
case 6:
|
|
|
|
return FUNCTION_WAITVBLANK;
|
|
|
|
break;
|
2011-11-06 21:37:50 +00:00
|
|
|
case 8:
|
|
|
|
return FUNCTION_REGISTERVBLANKHANDLER;
|
|
|
|
break;
|
2020-04-22 19:46:46 +02:00
|
|
|
case 9:
|
|
|
|
return FUNCTION_RELEASEVBLANKHANDLER;
|
|
|
|
break;
|
2017-03-01 19:33:46 -05:00
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
break;
|
|
|
|
}
|
2008-12-01 04:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CVblank::Invoke(CMIPS& context, unsigned int functionId)
|
|
|
|
{
|
2017-03-01 19:33:46 -05:00
|
|
|
switch(functionId)
|
|
|
|
{
|
|
|
|
case 4:
|
2017-03-02 20:26:50 -05:00
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = WaitVblankStart();
|
2017-03-01 19:33:46 -05:00
|
|
|
break;
|
|
|
|
case 5:
|
2017-03-02 20:26:50 -05:00
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = WaitVblankEnd();
|
2017-03-01 19:33:46 -05:00
|
|
|
break;
|
2017-03-04 23:41:09 -05:00
|
|
|
case 6:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = WaitVblank();
|
|
|
|
break;
|
2011-11-06 21:37:50 +00:00
|
|
|
case 8:
|
2017-03-01 19:33:46 -05:00
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = RegisterVblankHandler(
|
2018-04-30 21:01:23 +01:00
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0,
|
|
|
|
context.m_State.nGPR[CMIPS::A1].nV0,
|
|
|
|
context.m_State.nGPR[CMIPS::A2].nV0,
|
|
|
|
context.m_State.nGPR[CMIPS::A3].nV0);
|
2011-11-06 21:37:50 +00:00
|
|
|
break;
|
2020-04-22 19:46:46 +02:00
|
|
|
case 9:
|
|
|
|
context.m_State.nGPR[CMIPS::V0].nD0 = ReleaseVblankHandler(
|
|
|
|
context.m_State.nGPR[CMIPS::A0].nV0,
|
|
|
|
context.m_State.nGPR[CMIPS::A1].nV0);
|
|
|
|
break;
|
2017-03-01 19:33:46 -05:00
|
|
|
default:
|
2018-05-24 12:59:15 -04:00
|
|
|
CLog::GetInstance().Warn(LOG_NAME, "Unknown function called (%d).\r\n", functionId);
|
2017-03-01 19:33:46 -05:00
|
|
|
break;
|
|
|
|
}
|
2008-12-01 04:00:36 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 20:26:50 -05:00
|
|
|
int32 CVblank::WaitVblankStart()
|
2008-12-08 03:43:30 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2011-05-05 04:28:11 +00:00
|
|
|
CLog::GetInstance().Print(LOG_NAME, FUNCTION_WAITVBLANKSTART "();\r\n");
|
2008-12-08 03:43:30 +00:00
|
|
|
#endif
|
2011-05-05 04:28:11 +00:00
|
|
|
m_bios.SleepThreadTillVBlankStart();
|
2017-03-02 20:26:50 -05:00
|
|
|
return 0;
|
2008-12-08 03:43:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-02 20:26:50 -05:00
|
|
|
int32 CVblank::WaitVblankEnd()
|
2008-12-01 04:00:36 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2011-05-05 04:28:11 +00:00
|
|
|
CLog::GetInstance().Print(LOG_NAME, FUNCTION_WAITVBLANKEND "();\r\n");
|
2008-12-01 04:00:36 +00:00
|
|
|
#endif
|
2011-05-05 04:28:11 +00:00
|
|
|
m_bios.SleepThreadTillVBlankEnd();
|
2017-03-02 20:26:50 -05:00
|
|
|
return 0;
|
2008-12-01 04:00:36 +00:00
|
|
|
}
|
2011-11-06 21:37:50 +00:00
|
|
|
|
2017-03-04 23:41:09 -05:00
|
|
|
int32 CVblank::WaitVblank()
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
CLog::GetInstance().Print(LOG_NAME, FUNCTION_WAITVBLANK "();\r\n");
|
|
|
|
#endif
|
|
|
|
//TODO: Skip waiting if we're already in Vblank
|
|
|
|
m_bios.SleepThreadTillVBlankStart();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-17 12:41:13 -04:00
|
|
|
int32 CVblank::RegisterVblankHandler(uint32 startEnd, uint32 priority, uint32 handlerPtr, uint32 handlerParam)
|
2011-11-06 21:37:50 +00:00
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
2017-05-29 06:01:32 +01:00
|
|
|
CLog::GetInstance().Print(LOG_NAME, FUNCTION_REGISTERVBLANKHANDLER "(startEnd = %d, priority = %d, handler = 0x%08X, arg = 0x%08X).\r\n",
|
2018-04-30 21:01:23 +01:00
|
|
|
startEnd, priority, handlerPtr, handlerParam);
|
2011-11-06 21:37:50 +00:00
|
|
|
#endif
|
2018-07-17 12:41:13 -04:00
|
|
|
return m_bios.RegisterVblankHandler(startEnd, priority, handlerPtr, handlerParam);
|
2011-11-06 21:37:50 +00:00
|
|
|
}
|
2020-04-22 19:46:46 +02:00
|
|
|
|
|
|
|
int32 CVblank::ReleaseVblankHandler(uint32 startEnd, uint32 handlerPtr)
|
|
|
|
{
|
|
|
|
#ifdef _DEBUG
|
|
|
|
CLog::GetInstance().Print(LOG_NAME, FUNCTION_RELEASEVBLANKHANDLER "(startEnd = %d, handler = 0x%08X).\r\n",
|
|
|
|
startEnd, handlerPtr);
|
|
|
|
#endif
|
|
|
|
return m_bios.ReleaseVblankHandler(startEnd, handlerPtr);
|
|
|
|
}
|