Skip to content
This repository was archived by the owner on Sep 11, 2023. It is now read-only.

Commit 1a21018

Browse files
committed
Refactor starting phase
1 parent b926828 commit 1a21018

File tree

8 files changed

+17
-32
lines changed

8 files changed

+17
-32
lines changed

Core/BaseVideoFilter.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,11 @@ bool BaseVideoFilter::IsOddFrame()
5252
return _isOddFrame;
5353
}
5454

55-
uint8_t BaseVideoFilter::GetFieldPhase()
56-
{
57-
return _fieldPhase;
58-
}
59-
6055
void BaseVideoFilter::SendFrame(uint16_t *ppuOutputBuffer, uint32_t frameNumber)
6156
{
6257
_frameLock.Acquire();
6358
_overscan = _console->GetSettings()->GetOverscanDimensions();
6459
_isOddFrame = frameNumber & 0x01;
65-
_fieldPhase = frameNumber % 3;
6660
UpdateBufferSize();
6761
OnBeforeApplyFilter();
6862
ApplyFilter(ppuOutputBuffer);

Core/BaseVideoFilter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class BaseVideoFilter
1515
SimpleLock _frameLock;
1616
OverscanDimensions _overscan;
1717
bool _isOddFrame;
18-
// https://forums.nesdev.org/viewtopic.php?p=30625#p30625
19-
uint8_t _fieldPhase;
2018

2119
void UpdateBufferSize();
2220

@@ -25,7 +23,6 @@ class BaseVideoFilter
2523

2624
virtual void ApplyFilter(uint16_t *ppuOutputBuffer) = 0;
2725
virtual void OnBeforeApplyFilter();
28-
uint8_t GetFieldPhase();
2926

3027
public:
3128
BaseVideoFilter(shared_ptr<Console> console);

Core/BisqwitNtscFilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ BisqwitNtscFilter::BisqwitNtscFilter(shared_ptr<Console> console, int resDivider
5050
} else {
5151
outputBuffer += GetOverscan().GetScreenWidth() * 64 / _resDivider / _resDivider * (120 - GetOverscan().Top);
5252
}
53-
DecodeFrame(120, 239 - GetOverscan().Bottom, _ppuOutputBuffer, outputBuffer, (_console->IsDotBypassed() ? (GetFieldPhase() * 4) : (IsOddFrame() ? 0 : 8)) + 327360);
53+
DecodeFrame(120, 239 - GetOverscan().Bottom, _ppuOutputBuffer, outputBuffer, (_console->GetStartingPhase() * 4) + 327360);
5454

5555
_workDone = true;
5656
}
@@ -70,7 +70,7 @@ void BisqwitNtscFilter::ApplyFilter(uint16_t *ppuOutputBuffer)
7070

7171
_workDone = false;
7272
_waitWork.Signal();
73-
DecodeFrame(GetOverscan().Top, 120, ppuOutputBuffer, GetOutputBuffer(), (_console->IsDotBypassed() ? (GetFieldPhase() * 4) : (IsOddFrame() ? 0 : 8)) + GetOverscan().Top * 341 * 8);
73+
DecodeFrame(GetOverscan().Top, 120, ppuOutputBuffer, GetOutputBuffer(), (_console->GetStartingPhase() * 4) + GetOverscan().Top * 341 * 8);
7474
while(!_workDone) {}
7575
}
7676

Core/Console.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ uint32_t Console::GetFrameCount()
568568
return _ppu ? _ppu->GetFrameCount() : 0;
569569
}
570570

571-
bool Console::IsDotBypassed()
571+
uint8_t Console::GetStartingPhase()
572572
{
573-
return _ppu ? _ppu->IsDotBypassed() : false;
573+
return _ppu ? _ppu->GetStartingPhase() : 0;
574574
}
575575

576576
NesModel Console::GetModel()

Core/Console.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class Console : public std::enable_shared_from_this<Console>
205205
RomInfo GetRomInfo();
206206
uint32_t GetFrameCount();
207207
// https://forums.nesdev.org/viewtopic.php?p=30625#p30625
208-
bool IsDotBypassed();
208+
uint8_t GetStartingPhase();
209209
NesModel GetModel();
210210

211211
uint32_t GetLagCounter();

Core/NtscFilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void NtscFilter::OnBeforeApplyFilter()
132132

133133
void NtscFilter::ApplyFilter(uint16_t *ppuOutputBuffer)
134134
{
135-
nes_ntsc_blit(&_ntscData, ppuOutputBuffer, _ntsc_border, PPU::ScreenWidth, (_console->IsDotBypassed() ? GetFieldPhase() : (IsOddFrame() ? 0 : 2)), PPU::ScreenWidth, 240, _ntscBuffer, NES_NTSC_OUT_WIDTH(PPU::ScreenWidth)*4);
135+
nes_ntsc_blit(&_ntscData, ppuOutputBuffer, _ntsc_border, PPU::ScreenWidth, _console->GetStartingPhase(), PPU::ScreenWidth, 240, _ntscBuffer, NES_NTSC_OUT_WIDTH(PPU::ScreenWidth)*4);
136136
GenerateArgbFrame(_ntscBuffer);
137137
}
138138

Core/PPU.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void PPU::Reset()
105105
memset(_oamDecayCycles, 0, sizeof(_oamDecayCycles));
106106
_enableOamDecay = _settings->CheckFlag(EmulationFlags::EnableOamDecay);
107107

108-
_isDotBypassed = false;
108+
_startingPhase = 0;
109109

110110
UpdateMinimumDrawCycles();
111111
}
@@ -999,21 +999,13 @@ void PPU::ProcessScanline()
999999
LoadTileInfo();
10001000
}
10011001
} else if(_cycle == 337 || _cycle == 339) {
1002-
if(_scanline == -1 && _cycle == 339 && (_frameCount & 0x01) && _nesModel == NesModel::NTSC && _settings->GetPpuModel() == PpuModel::Ppu2C02) {
1003-
if (IsRenderingEnabled()) {
1004-
//This behavior is NTSC-specific - PAL frames are always the same number of cycles
1005-
//"With rendering enabled, each odd PPU frame is one PPU clock shorter than normal" (skip from 339 to 0, going over 340)
1006-
_cycle = 340;
1007-
_isDotBypassed = false;
1008-
}
1009-
else {
1010-
// "By keeping rendering disabled until after the time when the clock is skipped on odd frames,
1011-
// you can get a different color dot crawl pattern than normal."
1012-
_isDotBypassed = true;
1013-
}
1014-
}
10151002
if (IsRenderingEnabled()) {
10161003
ReadVram(GetNameTableAddr());
1004+
if (_scanline == -1 && _cycle == 339 && (_frameCount & 0x01) && _nesModel == NesModel::NTSC && _settings->GetPpuModel() == PpuModel::Ppu2C02) {
1005+
//This behavior is NTSC-specific - PAL frames are always the same number of cycles
1006+
//"With rendering enabled, each odd PPU frame is one PPU clock shorter than normal" (skip from 339 to 0, going over 340)
1007+
_cycle = 340;
1008+
}
10171009
}
10181010
}
10191011
}
@@ -1351,6 +1343,8 @@ void PPU::Exec()
13511343
}
13521344
}
13531345

1346+
_startingPhase = _cycle % 3;
1347+
13541348
if(_needStateUpdate) {
13551349
UpdateState();
13561350
}

Core/PPU.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class PPU : public IMemoryHandler, public Snapshotable
110110
bool _corruptOamRow[32];
111111

112112
// https://forums.nesdev.org/viewtopic.php?p=30625#p30625
113-
bool _isDotBypassed;
113+
uint8_t _startingPhase;
114114

115115
void UpdateStatusFlag();
116116

@@ -220,9 +220,9 @@ class PPU : public IMemoryHandler, public Snapshotable
220220
return _frameCount;
221221
}
222222

223-
bool IsDotBypassed()
223+
uint8_t GetStartingPhase()
224224
{
225-
return _isDotBypassed;
225+
return _startingPhase;
226226
}
227227

228228
uint32_t GetFrameCycle()

0 commit comments

Comments
 (0)