Improve ystart detection:

* Fix transition locked -> floating
    * Lock detected value after 30 stable frames
This commit is contained in:
Christian Speckner 2017-03-06 00:21:05 +01:00
parent e18fe2005d
commit d429b79d78
2 changed files with 38 additions and 12 deletions

View File

@ -22,13 +22,13 @@
enum Metrics: uInt32 { enum Metrics: uInt32 {
maxUnderscan = 10, maxUnderscan = 10,
maxVblankViolations = 2, maxVblankViolations = 2,
minStableVblankFrames = 1 minStableVblankFrames = 1,
framesUntilFinal = 30
}; };
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
VblankManager::VblankManager() VblankManager::VblankManager()
: myVblankLines(0), : myVblankLines(0),
//myMaxUnderscan(0),
myYstart(0), myYstart(0),
myMode(VblankMode::floating) myMode(VblankMode::floating)
{ {
@ -46,7 +46,7 @@ void VblankManager::reset()
myLastVblankLines = 0; myLastVblankLines = 0;
myIsRunning = false; myIsRunning = false;
if (myMode != VblankMode::fixed) myMode = VblankMode::floating; if (myMode != VblankMode::fixed) setVblankMode(VblankMode::floating);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -54,6 +54,10 @@ void VblankManager::start()
{ {
myCurrentLine = 0; myCurrentLine = 0;
myIsRunning = true; myIsRunning = true;
myVblankViolated = false;
if (myMode == VblankMode::locked && ++myFramesInLockedMode > Metrics::framesUntilFinal)
setVblankMode(VblankMode::final);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -63,9 +67,7 @@ bool VblankManager::nextLine(bool isGarbageFrame)
myCurrentLine++; myCurrentLine++;
const bool transition = const bool transition = shouldTransition(isGarbageFrame);
myMode == VblankMode::fixed ? (myCurrentLine >= myYstart) : shouldTransition(isGarbageFrame);
if (transition) myIsRunning = false; if (transition) myIsRunning = false;
return transition; return transition;
@ -78,7 +80,7 @@ void VblankManager::setYstart(uInt32 ystart)
myYstart = ystart; myYstart = ystart;
myMode = ystart ? VblankMode::fixed : VblankMode::floating; setVblankMode(ystart ? VblankMode::fixed : VblankMode::floating);
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -119,7 +121,7 @@ bool VblankManager::shouldTransition(bool isGarbageFrame)
} }
if (myStableVblankFrames >= Metrics::minStableVblankFrames) { if (myStableVblankFrames >= Metrics::minStableVblankFrames) {
myMode = VblankMode::locked; setVblankMode(VblankMode::locked);
myVblankViolations = 0; myVblankViolations = 0;
} }
@ -147,20 +149,41 @@ bool VblankManager::shouldTransition(bool isGarbageFrame)
} }
if (myVblankViolations > Metrics::maxVblankViolations) { if (myVblankViolations > Metrics::maxVblankViolations) {
myMode = VblankMode::floating; setVblankMode(VblankMode::floating);
myStableVblankFrames = 0; myStableVblankFrames = 0;
} }
break; break;
default: case VblankMode::fixed:
transition = false; transition = myCurrentLine >= myYstart;
break;
case VblankMode::final:
transition = myCurrentLine >= myLastVblankLines;
break; break;
} }
return transition; return transition;
} }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void VblankManager::setVblankMode(VblankMode mode)
{
if (myMode == mode) return;
myMode = mode;
switch (myMode) {
case VblankMode::locked:
myFramesInLockedMode = 0;
break;
default:
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TODO: implement this once the class is finalized // TODO: implement this once the class is finalized
bool VblankManager::save(Serializer& out) const bool VblankManager::save(Serializer& out) const

View File

@ -61,6 +61,7 @@ class VblankManager : public Serializable
enum VblankMode { enum VblankMode {
locked, locked,
floating, floating,
final,
fixed fixed
}; };
@ -68,10 +69,11 @@ class VblankManager : public Serializable
bool shouldTransition(bool isGarbageFrame); bool shouldTransition(bool isGarbageFrame);
void setVblankMode(VblankMode mode);
private: private:
uInt32 myVblankLines; uInt32 myVblankLines;
//uInt32 myMaxUnderscan;
uInt32 myYstart; uInt32 myYstart;
bool myVblank; bool myVblank;
uInt32 myCurrentLine; uInt32 myCurrentLine;
@ -81,6 +83,7 @@ class VblankManager : public Serializable
uInt8 myVblankViolations; uInt8 myVblankViolations;
uInt8 myStableVblankFrames; uInt8 myStableVblankFrames;
bool myVblankViolated; bool myVblankViolated;
uInt8 myFramesInLockedMode;
bool myIsRunning; bool myIsRunning;