Skip to content

Commit

Permalink
PCE: Tweak trigger for RCR counter increments
Browse files Browse the repository at this point in the history
The RCR counter doesn't appear to increment unless the HDW mode (e.g the visible scanline) actually starts. On the other hand, the vertical mode counter will get clocked even if the VDC doesn't hit HDW (trigger seems to be earlier, currently set to be the same timing as the Y scroll latch). The RCR IRQ could occur later than on hardware because of this
  • Loading branch information
SourMesen committed Oct 19, 2024
1 parent 860b735 commit c9adff3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 15 additions & 7 deletions Core/PCE/PceVdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void PceVdc::ProcessEvent()

switch(_nextEvent) {
case PceVdcEvent::LatchScrollY:
_needRcrIncrement = true;
_needVCounterClock = true;
_latchClockY = _state.HClock;
IncScrollY();
if(!_state.BurstModeEnabled) {
Expand All @@ -157,7 +157,6 @@ void PceVdc::ProcessEvent()
break;

case PceVdcEvent::HdsIrqTrigger:
_needRcrIncrement = true;
if(_evalStartCycle >= 1365) {
//New row was about to start, but no time to start sprite eval, next row will have no sprites
_spriteCount = 0;
Expand Down Expand Up @@ -185,6 +184,7 @@ void PceVdc::SetHorizontalMode(PceVdcModeH hMode)
break;

case PceVdcModeH::Hdw:
_needVCounterClock = true;
_needRcrIncrement = true;
_nextEvent = PceVdcEvent::IncRcrCounter;
_nextEventCounter = DotsToClocks((_state.HvLatch.HorizDisplayWidth - 1) * 8) + 2;
Expand Down Expand Up @@ -664,16 +664,21 @@ void PceVdc::SetVertMode(PceVdcModeV vMode)
}
}

void PceVdc::IncrementRcrCounter()
void PceVdc::ClockVCounter()
{
_state.RcrCounter++;

_needRcrIncrement = false;

_vModeCounter--;
if(_vModeCounter == 0) {
SetVertMode((PceVdcModeV)(((int)_vMode + 1) % 4));
}
_needVCounterClock = false;
}

void PceVdc::IncrementRcrCounter()
{
_state.RcrCounter++;

_needRcrIncrement = false;
ClockVCounter();

if(_vMode == PceVdcModeV::Vde && _state.RcrCounter == _state.HvLatch.VertDisplayWidth + 1) {
_needVertBlankIrq = true;
Expand Down Expand Up @@ -732,6 +737,8 @@ void PceVdc::ProcessEndOfScanline()

if(_needRcrIncrement) {
IncrementRcrCounter();
} else if(_needVCounterClock) {
ClockVCounter();
}

if(_hMode == PceVdcModeH::Hdw) {
Expand Down Expand Up @@ -1385,6 +1392,7 @@ void PceVdc::Serialize(Serializer& s)

SV(_screenOffsetX);
SV(_needRcrIncrement);
SV(_needVCounterClock);
SV(_needVertBlankIrq);
SV(_verticalBlankDone);

Expand Down
2 changes: 2 additions & 0 deletions Core/PCE/PceVdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class PceVdc final : public ISerializable

uint16_t _screenOffsetX = 0;
bool _needRcrIncrement = false;
bool _needVCounterClock = false;
bool _needVertBlankIrq = false;
bool _verticalBlankDone = false;

Expand Down Expand Up @@ -156,6 +157,7 @@ class PceVdc final : public ISerializable
__noinline void ProcessVramDmaTransfer();
__noinline void SetVertMode(PceVdcModeV vMode);
__noinline void SetHorizontalMode(PceVdcModeH hMode);
void ClockVCounter();

__noinline void ProcessVdcEvents();
__noinline void ProcessEvent();
Expand Down

0 comments on commit c9adff3

Please sign in to comment.