Skip to content

Commit

Permalink
Periodically signal hsync instead of having it always on.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed Oct 13, 2023
1 parent ddf2966 commit 1eec610
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
23 changes: 19 additions & 4 deletions Source/PS2VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,23 @@ void CPS2VM::SetEeFrequencyScale(uint32 numerator, uint32 denominator)

void CPS2VM::ReloadFrameRateLimit()
{
uint32 frameRate = 60;
uint32 hRefreshRate = PS2::GS_NTSC_HSYNC_FREQ;
uint32 vRefreshRate = 60;
if(m_ee && m_ee->m_gs)
{
frameRate = m_ee->m_gs->GetCrtFrameRate();
hRefreshRate = m_ee->m_gs->GetCrtHSyncFrequency();
vRefreshRate = m_ee->m_gs->GetCrtFrameRate();
}
bool limitFrameRate = CAppConfig::GetInstance().GetPreferenceBoolean(PREF_PS2_LIMIT_FRAMERATE);
m_frameLimiter.SetFrameRate(limitFrameRate ? frameRate : 0);
m_frameLimiter.SetFrameRate(limitFrameRate ? vRefreshRate : 0);

//At 1x scale, IOP runs 8 times slower than EE
uint32 eeFreqScaled = PS2::EE_CLOCK_FREQ * m_eeFreqScaleNumerator / m_eeFreqScaleDenominator;
m_iopTickStep = (m_eeTickStep / 8) * m_eeFreqScaleDenominator / m_eeFreqScaleNumerator;

uint32 frameTicks = eeFreqScaled / frameRate;
m_hblankTicksTotal = eeFreqScaled / hRefreshRate;

uint32 frameTicks = eeFreqScaled / vRefreshRate;
m_onScreenTicksTotal = frameTicks * 9 / 10;
m_vblankTicksTotal = frameTicks / 10;

Expand Down Expand Up @@ -481,6 +485,7 @@ void CPS2VM::ResetVM()

SetEeFrequencyScale(1, 1);

m_hblankTicks = m_hblankTicksTotal;
m_vblankTicks = m_onScreenTicksTotal;
m_spuUpdateTicks = m_spuUpdateTicksTotal;
m_inVblank = false;
Expand Down Expand Up @@ -715,6 +720,7 @@ void CPS2VM::UpdateEe()
m_eeExecutionTicks -= executed;
m_spuUpdateTicks -= (static_cast<int64>(executed) << SPU_UPDATE_TICKS_PRECISION);
m_ee->CountTicks(executed);
m_hblankTicks -= executed;
m_vblankTicks -= executed;

#ifdef DEBUGGER_INCLUDED
Expand Down Expand Up @@ -897,6 +903,15 @@ void CPS2VM::EmuThread()
}

{
if(m_hblankTicks <= 0)
{
if(m_ee->m_gs)
{
m_ee->m_gs->SetHBlank();
m_hblankTicks += m_hblankTicksTotal;
}
}

//Check vblank stuff
if(m_vblankTicks <= 0)
{
Expand Down
2 changes: 2 additions & 0 deletions Source/PS2VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ class CPS2VM : public CVirtualMachine
uint32 m_eeFreqScaleDenominator = 1;
uint32 m_eeRamSize = PS2::EE_BASE_RAM_SIZE;
uint32 m_iopRamSize = PS2::IOP_BASE_RAM_SIZE;
uint32 m_hblankTicksTotal = 0;
uint32 m_onScreenTicksTotal = 0;
uint32 m_vblankTicksTotal = 0;
int m_hblankTicks = 0;
int m_vblankTicks = 0;
bool m_inVblank = false;
int64 m_spuUpdateTicks = 0;
Expand Down
24 changes: 16 additions & 8 deletions Source/gs/GSHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ void CGSHandler::SetDrawEnabled(bool drawEnabled)
m_drawEnabled = drawEnabled;
}

void CGSHandler::SetHBlank()
{
std::lock_guard registerMutexLock(m_registerMutex);
m_nCSR |= CSR_HSYNC_INT;
NotifyEvent(CSR_HSYNC_INT);
}

void CGSHandler::SetVBlank()
{
{
Expand Down Expand Up @@ -412,14 +419,11 @@ uint32 CGSHandler::ReadPrivRegister(uint32 nAddress)
{
case GS_CSR:
case GS_CSR_ALT:
//Force CSR to have the H-Blank bit set.
{
std::lock_guard registerMutexLock(m_registerMutex);
m_nCSR |= CSR_HSYNC_INT;
NotifyEvent(CSR_HSYNC_INT);
R_REG(nAddress, nData, m_nCSR);
}
break;
{
std::lock_guard registerMutexLock(m_registerMutex);
R_REG(nAddress, nData, m_nCSR);
}
break;
case GS_IMR:
R_REG(nAddress, nData, m_nIMR);
break;
Expand Down Expand Up @@ -470,6 +474,10 @@ void CGSHandler::WritePrivRegister(uint32 nAddress, uint32 nData)
{
m_nCSR &= ~CSR_FINISH_EVENT;
}
if(nData & CSR_HSYNC_INT)
{
m_nCSR &= ~CSR_HSYNC_INT;
}
if(nData & CSR_VSYNC_INT)
{
m_nCSR &= ~CSR_VSYNC_INT;
Expand Down
1 change: 1 addition & 0 deletions Source/gs/GSHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ class CGSHandler
void SetLoggingEnabled(bool);
static std::string DisassembleWrite(uint8, uint64);

void SetHBlank();
void SetVBlank();
void ResetVBlank();

Expand Down

0 comments on commit 1eec610

Please sign in to comment.