Skip to content

Commit

Permalink
PCE: Block vram accesses at the start of horizontal sync
Browse files Browse the repository at this point in the history
Makes timing test rom results match hardware a bit better
  • Loading branch information
SourMesen committed Dec 23, 2023
1 parent 0cb1c2b commit d3a6aad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Core/PCE/PceVdc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void PceVdc::SetHorizontalMode(PceVdcModeH hMode)
_loadBgStart = UINT16_MAX;
_evalStartCycle = UINT16_MAX;
_hModeCounter = DotsToClocks((_state.HvLatch.HorizSyncWidth + 1) * 8);
_hSyncStartClock = _console->GetMasterClock();
ProcessHorizontalSyncStart();
//LogDebug("H: " + std::to_string(_state.HClock) + " - HSW");
break;
Expand Down Expand Up @@ -728,7 +729,11 @@ void PceVdc::ProcessEndOfScanline()

//VCE sets HBLANK to low every 1365 clocks, interrupting what
//the VDC was doing and starting a HSW phase
_hMode = PceVdcModeH::Hsw;
if(_hMode != PceVdcModeH::Hsw) {
_hMode = PceVdcModeH::Hsw;
_hSyncStartClock = _console->GetMasterClock();
}

_loadBgStart = UINT16_MAX;
_evalStartCycle = UINT16_MAX;

Expand Down Expand Up @@ -971,6 +976,11 @@ void PceVdc::ProcessVramAccesses()
}

if(!accessBlocked) {
if(_hMode == PceVdcModeH::Hds && _console->GetMasterClock() - _hSyncStartClock < 8 * GetClockDivider()) {
//VRAM accesses appear to be blocked during the first 8 dots of horizontal sync
return;
}

if(_pendingMemoryRead) {
ProcessVramRead();
} else if(_pendingMemoryWrite) {
Expand Down Expand Up @@ -1337,6 +1347,7 @@ void PceVdc::Serialize(Serializer& s)

SV(_nextEvent);
SV(_nextEventCounter);
SV(_hSyncStartClock);

SV(_drawSpriteCount);
SV(_totalSpriteCount);
Expand Down
1 change: 1 addition & 0 deletions Core/PCE/PceVdc.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PceVdc final : public ISerializable

PceVdcEvent _nextEvent = PceVdcEvent::None;
uint16_t _nextEventCounter = 0;
uint64_t _hSyncStartClock = 0;

bool _isVdc2 = false;
MemoryType _vramType = MemoryType::PceVideoRam;
Expand Down

0 comments on commit d3a6aad

Please sign in to comment.