Merge pull request #1442 from ssakash/Counters

PCSX2-Counters: Improve video mode detection
This commit is contained in:
ramapcsx2 2016-07-18 19:28:24 +02:00 committed by GitHub
commit ddc68626d8
8 changed files with 131 additions and 89 deletions

View File

@ -25,7 +25,7 @@
#include "CDVD_internal.h" #include "CDVD_internal.h"
#include "CDVDisoReader.h" #include "CDVDisoReader.h"
#include "GS.h" // for gsRegionMode #include "GS.h" // for gsVideoMode
#include "Elfheader.h" #include "Elfheader.h"
#include "ps2/BiosTools.h" #include "ps2/BiosTools.h"
#include "GameDatabase.h" #include "GameDatabase.h"
@ -958,7 +958,7 @@ u8 monthmap[13] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
void cdvdVsync() { void cdvdVsync() {
cdvd.RTCcount++; cdvd.RTCcount++;
if (cdvd.RTCcount < ((gsRegionMode == Region_NTSC) ? 60 : 50)) return; if (cdvd.RTCcount < ((gsVideoMode == GS_VideoMode::NTSC) ? 60 : 50)) return;
cdvd.RTCcount = 0; cdvd.RTCcount = 0;
if ( cdvd.Status == CDVD_STATUS_TRAY_OPEN ) if ( cdvd.Status == CDVD_STATUS_TRAY_OPEN )

View File

@ -288,11 +288,6 @@ struct Pcsx2Config
bool FrameSkipEnable; bool FrameSkipEnable;
bool VsyncEnable; bool VsyncEnable;
// The region mode controls the default Maximum/Minimum FPS settings and also
// regulates the vsync rates (which in turn control the IOP's SPU2 tick sync and ensure
// proper audio playback speed).
int DefaultRegionMode; // 0=NTSC and 1=PAL
int FramesToDraw; // number of consecutive frames (fields) to render int FramesToDraw; // number of consecutive frames (fields) to render
int FramesToSkip; // number of consecutive frames (fields) to skip int FramesToSkip; // number of consecutive frames (fields) to skip
@ -318,7 +313,6 @@ struct Pcsx2Config
OpEqu( FramerateNTSC ) && OpEqu( FramerateNTSC ) &&
OpEqu( FrameratePAL ) && OpEqu( FrameratePAL ) &&
OpEqu( DefaultRegionMode ) &&
OpEqu( FramesToDraw ) && OpEqu( FramesToDraw ) &&
OpEqu( FramesToSkip ); OpEqu( FramesToSkip );
} }

View File

@ -58,6 +58,13 @@ static void rcntWmode(int index, u32 value);
static void rcntWtarget(int index, u32 value); static void rcntWtarget(int index, u32 value);
static void rcntWhold(int index, u32 value); static void rcntWhold(int index, u32 value);
static bool IsAnalogVideoMode()
{
if (gsVideoMode == GS_VideoMode::PAL || gsVideoMode == GS_VideoMode::NTSC)
return true;
return false;
}
void rcntReset(int index) { void rcntReset(int index) {
counters[index].count = 0; counters[index].count = 0;
@ -155,9 +162,6 @@ void rcntInit()
vsyncCounter.Mode = MODE_VRENDER; vsyncCounter.Mode = MODE_VRENDER;
vsyncCounter.sCycle = cpuRegs.cycle; vsyncCounter.sCycle = cpuRegs.cycle;
// Set the video mode to user's default request:
gsSetRegionMode( (GS_RegionMode)EmuConfig.GS.DefaultRegionMode );
for (i=0; i<4; i++) rcntReset(i); for (i=0; i<4; i++) rcntReset(i);
cpuRcntSet(); cpuRcntSet();
} }
@ -173,7 +177,7 @@ static u64 m_iStart=0;
struct vSyncTimingInfo struct vSyncTimingInfo
{ {
Fixed100 Framerate; // frames per second (8 bit fixed) Fixed100 Framerate; // frames per second (8 bit fixed)
GS_RegionMode RegionMode; // used to detect change (interlaced/progressive) GS_VideoMode VideoMode; // used to detect change (interlaced/progressive)
u32 Render; // time from vblank end to vblank start (cycles) u32 Render; // time from vblank end to vblank start (cycles)
u32 Blank; // time from vblank start to vblank end (cycles) u32 Blank; // time from vblank start to vblank end (cycles)
@ -214,7 +218,7 @@ static void vSyncInfoCalc(vSyncTimingInfo* info, Fixed100 framesPerSecond, u32 s
u64 hBlank = Scanline / 2; u64 hBlank = Scanline / 2;
u64 hRender = Scanline - hBlank; u64 hRender = Scanline - hBlank;
if (gsRegionMode == Region_NTSC_PROGRESSIVE) if (!IsAnalogVideoMode())
{ {
hBlank /= 2; hBlank /= 2;
hRender /= 2; hRender /= 2;
@ -236,7 +240,7 @@ static void vSyncInfoCalc(vSyncTimingInfo* info, Fixed100 framesPerSecond, u32 s
else if ((hBlank - info->hBlank) >= 5000) info->hBlank++; else if ((hBlank - info->hBlank) >= 5000) info->hBlank++;
// Calculate accumulative hSync rounding error per half-frame: // Calculate accumulative hSync rounding error per half-frame:
if (gsRegionMode != Region_NTSC_PROGRESSIVE) // gets off the chart in that mode if (IsAnalogVideoMode()) // gets off the chart in that mode
{ {
u32 hSyncCycles = ((info->hRender + info->hBlank) * scansPerFrame) / 2; u32 hSyncCycles = ((info->hRender + info->hBlank) * scansPerFrame) / 2;
u32 vSyncCycles = (info->Render + info->Blank); u32 vSyncCycles = (info->Render + info->Blank);
@ -249,6 +253,22 @@ static void vSyncInfoCalc(vSyncTimingInfo* info, Fixed100 framesPerSecond, u32 s
// is thus not worth the effort at this time. // is thus not worth the effort at this time.
} }
static const char* ReportVideoMode()
{
switch (gsVideoMode)
{
case GS_VideoMode::PAL: return "PAL";
case GS_VideoMode::NTSC: return "NTSC";
case GS_VideoMode::VESA: return "VESA";
case GS_VideoMode::BIOS: return "BIOS";
case GS_VideoMode::HDTV_480P: return "HDTV 480p";
case GS_VideoMode::HDTV_576P: return "HDTV 576p";
case GS_VideoMode::HDTV_720P: return "HDTV 720p";
case GS_VideoMode::HDTV_1080I: return "HDTV 1080i";
case GS_VideoMode::HDTV_1080P: return "HDTV 1080p";
default: return "Unknown";
}
}
u32 UpdateVSyncRate() u32 UpdateVSyncRate()
{ {
@ -262,35 +282,64 @@ u32 UpdateVSyncRate()
u32 scanlines = 0; u32 scanlines = 0;
bool isCustom = false; bool isCustom = false;
if( gsRegionMode == Region_PAL ) //Set up scanlines and framerate based on video mode
switch (gsVideoMode)
{ {
case GS_VideoMode::Uninitialized: // SYSCALL instruction hasn't executed yet, give some temporary values.
framerate = 60;
scanlines = SCANLINES_TOTAL_NTSC;
break;
case GS_VideoMode::PAL:
isCustom = (EmuConfig.GS.FrameratePAL != 50.0); isCustom = (EmuConfig.GS.FrameratePAL != 50.0);
framerate = EmuConfig.GS.FrameratePAL / 2; framerate = EmuConfig.GS.FrameratePAL / 2;
scanlines = SCANLINES_TOTAL_PAL; scanlines = SCANLINES_TOTAL_PAL;
if (!gsIsInterlaced) scanlines += 3; if (!gsIsInterlaced) scanlines += 3;
} break;
else if ( gsRegionMode == Region_NTSC )
{ case GS_VideoMode::NTSC:
isCustom = (EmuConfig.GS.FramerateNTSC != 59.94); isCustom = (EmuConfig.GS.FramerateNTSC != 59.94);
framerate = EmuConfig.GS.FramerateNTSC / 2; framerate = EmuConfig.GS.FramerateNTSC / 2;
scanlines = SCANLINES_TOTAL_NTSC; scanlines = SCANLINES_TOTAL_NTSC;
if (!gsIsInterlaced) scanlines += 1; if (!gsIsInterlaced) scanlines += 1;
} break;
else if ( gsRegionMode == Region_NTSC_PROGRESSIVE )
{ case GS_VideoMode::HDTV_480P:
isCustom = (EmuConfig.GS.FramerateNTSC != 59.94); framerate = 29.97;
framerate = EmuConfig.GS.FramerateNTSC / 2;
scanlines = SCANLINES_TOTAL_NTSC; scanlines = SCANLINES_TOTAL_NTSC;
break;
case GS_VideoMode::HDTV_1080P:
case GS_VideoMode::HDTV_1080I:
case GS_VideoMode::HDTV_576P:
case GS_VideoMode::HDTV_720P:
case GS_VideoMode::VESA:
case GS_VideoMode::BIOS:
framerate = 30;
scanlines = SCANLINES_TOTAL_NTSC;
break;
// Falls through to unknown when unidentified mode parameter of SetGsCrt is detected.
case GS_VideoMode::Unknown:
// For Release builds, keep using the NTSC timing values when unknown video mode is detected.
// Assert will be triggered for debug/dev builds.
framerate = FRAMERATE_NTSC;
scanlines = SCANLINES_TOTAL_NTSC;
Console.Error("PCSX2-Counters: Unknown video mode detected");
default:
pxAssertDev(false , "Unknown video mode detected via SetGsCrt");
} }
if (vSyncInfo.Framerate != framerate || vSyncInfo.RegionMode != gsRegionMode) bool ActiveVideoMode = gsVideoMode != GS_VideoMode::Uninitialized;
if (vSyncInfo.Framerate != framerate || vSyncInfo.VideoMode != gsVideoMode)
{ {
vSyncInfo.RegionMode = gsRegionMode; vSyncInfo.VideoMode = gsVideoMode;
vSyncInfoCalc( &vSyncInfo, framerate, scanlines ); vSyncInfoCalc( &vSyncInfo, framerate, scanlines );
Console.WriteLn( Color_Green, "(UpdateVSyncRate) Mode Changed to %s.", ( gsRegionMode == Region_PAL ) ? "PAL" : if(ActiveVideoMode)
( gsRegionMode == Region_NTSC ) ? "NTSC" : "NTSC Progressive Scan" ); Console.WriteLn( Color_Green, "(UpdateVSyncRate) Mode Changed to %s.", ReportVideoMode());
if( isCustom ) if( isCustom && ActiveVideoMode)
Console.Indent().WriteLn( Color_StrongGreen, "... with user configured refresh rate: %.02f Hz", 2 * framerate.ToFloat() ); Console.Indent().WriteLn( Color_StrongGreen, "... with user configured refresh rate: %.02f Hz", 2 * framerate.ToFloat() );
hsyncCounter.CycleT = vSyncInfo.hRender; // Amount of cycles before the counter will be updated hsyncCounter.CycleT = vSyncInfo.hRender; // Amount of cycles before the counter will be updated
@ -309,7 +358,8 @@ u32 UpdateVSyncRate()
{ {
m_iTicks = ticks; m_iTicks = ticks;
gsOnModeChanged( vSyncInfo.Framerate, m_iTicks ); gsOnModeChanged( vSyncInfo.Framerate, m_iTicks );
Console.WriteLn( Color_Green, "(UpdateVSyncRate) FPS Limit Changed : %.02f fps", fpslimit.ToFloat()*2 ); if (ActiveVideoMode)
Console.WriteLn( Color_Green, "(UpdateVSyncRate) FPS Limit Changed : %.02f fps", fpslimit.ToFloat()*2 );
} }
m_iStart = GetCPUTicks(); m_iStart = GetCPUTicks();

View File

@ -32,15 +32,14 @@ void gsOnModeChanged( Fixed100 framerate, u32 newTickrate )
GetMTGS().SendSimplePacket( GS_RINGTYPE_MODECHANGE, framerate.Raw, newTickrate, 0 ); GetMTGS().SendSimplePacket( GS_RINGTYPE_MODECHANGE, framerate.Raw, newTickrate, 0 );
} }
bool gsIsInterlaced = false; bool gsIsInterlaced = false;
GS_RegionMode gsRegionMode = Region_NTSC;
void gsSetRegionMode( GS_RegionMode region ) void gsSetVideoMode(GS_VideoMode mode )
{ {
if( gsRegionMode == region ) return; if( gsVideoMode == mode ) return;
gsRegionMode = region; gsVideoMode = mode;
UpdateVSyncRate(); UpdateVSyncRate();
} }
@ -157,21 +156,8 @@ __fi void gsWrite8(u32 mem, u8 value)
static void _gsSMODEwrite( u32 mem, u32 value ) static void _gsSMODEwrite( u32 mem, u32 value )
{ {
switch (mem) if(mem == GS_SMODE2)
{
case GS_SMODE1:
if ( (value & 0x6000) == 0x6000 )
gsSetRegionMode( Region_PAL );
else if (value & 0x400000 || value & 0x200000)
gsSetRegionMode( Region_NTSC_PROGRESSIVE );
else
gsSetRegionMode( Region_NTSC );
break;
case GS_SMODE2:
gsIsInterlaced = (value & 0x1); gsIsInterlaced = (value & 0x1);
break;
}
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
@ -436,5 +422,5 @@ void gsResetFrameSkip()
void SaveStateBase::gsFreeze() void SaveStateBase::gsFreeze()
{ {
FreezeMem(PS2MEM_GS, 0x2000); FreezeMem(PS2MEM_GS, 0x2000);
Freeze(gsRegionMode); Freeze(gsVideoMode);
} }

View File

@ -217,14 +217,22 @@ struct GSRegSIGBLID
#define GSIMR ((u32&)*(PS2MEM_GS+0x1010)) #define GSIMR ((u32&)*(PS2MEM_GS+0x1010))
#define GSSIGLBLID ((GSRegSIGBLID&)*(PS2MEM_GS+0x1080)) #define GSSIGLBLID ((GSRegSIGBLID&)*(PS2MEM_GS+0x1080))
enum GS_RegionMode enum class GS_VideoMode : int
{ {
Region_NTSC, Uninitialized,
Region_PAL, Unknown,
Region_NTSC_PROGRESSIVE NTSC,
PAL,
VESA,
HDTV_480P,
HDTV_576P,
HDTV_720P,
HDTV_1080I,
HDTV_1080P,
BIOS
}; };
extern GS_RegionMode gsRegionMode; extern GS_VideoMode gsVideoMode;
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// MTGS Threaded Class Declaration // MTGS Threaded Class Declaration
@ -363,7 +371,7 @@ extern s32 gsOpen();
extern void gsClose(); extern void gsClose();
extern void gsReset(); extern void gsReset();
extern void gsOnModeChanged( Fixed100 framerate, u32 newTickrate ); extern void gsOnModeChanged( Fixed100 framerate, u32 newTickrate );
extern void gsSetRegionMode( GS_RegionMode isPal ); extern void gsSetVideoMode( GS_VideoMode mode );
extern void gsResetFrameSkip(); extern void gsResetFrameSkip();
extern void gsPostVsyncStart(); extern void gsPostVsyncStart();
extern void gsFrameSkip(); extern void gsFrameSkip();

View File

@ -206,7 +206,6 @@ Pcsx2Config::GSOptions::GSOptions()
DisableOutput = false; DisableOutput = false;
VsyncQueueSize = 2; VsyncQueueSize = 2;
DefaultRegionMode = Region_NTSC;
FramesToDraw = 2; FramesToDraw = 2;
FramesToSkip = 2; FramesToSkip = 2;
@ -231,10 +230,6 @@ void Pcsx2Config::GSOptions::LoadSave( IniInterface& ini )
IniEntry( FramerateNTSC ); IniEntry( FramerateNTSC );
IniEntry( FrameratePAL ); IniEntry( FrameratePAL );
// WARNING: array must be NULL terminated to compute it size
static const wxChar * const ntsc_pal_str[3] = { L"ntsc", L"pal", NULL };
ini.EnumEntry( L"DefaultRegionMode", DefaultRegionMode, ntsc_pal_str, DefaultRegionMode );
IniEntry( FramesToDraw ); IniEntry( FramesToDraw );
IniEntry( FramesToSkip ); IniEntry( FramesToSkip );
} }

View File

@ -22,7 +22,9 @@
#include "R5900.h" #include "R5900.h"
#include "R5900OpcodeTables.h" #include "R5900OpcodeTables.h"
#include "R5900Exceptions.h" #include "R5900Exceptions.h"
#include "GS.h"
GS_VideoMode gsVideoMode = GS_VideoMode::Uninitialized;
static __fi bool _add64_Overflow( s64 x, s64 y, s64 &ret ) static __fi bool _add64_Overflow( s64 x, s64 y, s64 &ret )
{ {
@ -886,42 +888,49 @@ void SYSCALL()
const char* field = (cpuRegs.GPR.n.a2.UL[0] & 1) ? "FRAME" : "FIELD"; const char* field = (cpuRegs.GPR.n.a2.UL[0] & 1) ? "FRAME" : "FIELD";
std::string mode; std::string mode;
// Warning info might be incorrect! // Warning info might be incorrect!
switch (cpuRegs.GPR.n.a1.UC[0]) { switch (cpuRegs.GPR.n.a1.UC[0])
case 0x2: mode = "NTSC 640x448 @ 59.940 (59.82)"; break; {
case 0x0:
case 0x2:
mode = "NTSC 640x448 @ 59.940 (59.82)"; gsSetVideoMode(GS_VideoMode::NTSC); break;
case 0x3: mode = "PAL 640x512 @ 50.000 (49.76)"; break; case 0x1:
case 0x3:
mode = "PAL 640x512 @ 50.000 (49.76)"; gsSetVideoMode(GS_VideoMode::PAL); break;
case 0x1A: mode = "VESA 640x480 @ 59.940"; break; case 0x1A: mode = "VESA 640x480 @ 59.940"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x1B: mode = "VESA 640x480 @ 72.809"; break; case 0x1B: mode = "VESA 640x480 @ 72.809"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x1C: mode = "VESA 640x480 @ 75.000"; break; case 0x1C: mode = "VESA 640x480 @ 75.000"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x1D: mode = "VESA 640x480 @ 85.008"; break; case 0x1D: mode = "VESA 640x480 @ 85.008"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x2A: mode = "VESA 800x600 @ 56.250"; break; case 0x2A: mode = "VESA 800x600 @ 56.250"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x2B: mode = "VESA 800x600 @ 60.317"; break; case 0x2B: mode = "VESA 800x600 @ 60.317"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x2C: mode = "VESA 800x600 @ 72.188"; break; case 0x2C: mode = "VESA 800x600 @ 72.188"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x2D: mode = "VESA 800x600 @ 75.000"; break; case 0x2D: mode = "VESA 800x600 @ 75.000"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x2E: mode = "VESA 800x600 @ 85.061"; break; case 0x2E: mode = "VESA 800x600 @ 85.061"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x3B: mode = "VESA 1024x768 @ 60.004"; break; case 0x3B: mode = "VESA 1024x768 @ 60.004"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x3C: mode = "VESA 1024x768 @ 70.069"; break; case 0x3C: mode = "VESA 1024x768 @ 70.069"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x3D: mode = "VESA 1024x768 @ 75.029"; break; case 0x3D: mode = "VESA 1024x768 @ 75.029"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x3E: mode = "VESA 1024x768 @ 84.997"; break; case 0x3E: mode = "VESA 1024x768 @ 84.997"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x4A: mode = "VESA 1280x1024 @ 63.981"; break; case 0x4A: mode = "VESA 1280x1024 @ 63.981"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x4B: mode = "VESA 1280x1024 @ 79.976"; break; case 0x4B: mode = "VESA 1280x1024 @ 79.976"; gsSetVideoMode(GS_VideoMode::VESA); break;
case 0x50: mode = "HDTV 720x480 @ 59.94"; break; case 0x50: mode = "HDTV 720x480 @ 59.94"; gsSetVideoMode(GS_VideoMode::HDTV_480P); break;
case 0x51: mode = "HDTV 1920x1080 @ 60.00"; break; case 0x51: mode = "HDTV 1920x1080 @ 60.00"; gsSetVideoMode(GS_VideoMode::HDTV_1080I); break;
case 0x52: mode = "HDTV 1280x720 @ ??.???"; break; case 0x52: mode = "HDTV 1280x720 @ ??.???"; gsSetVideoMode(GS_VideoMode::HDTV_720P); break;
case 0x53: mode = "HDTV 768x576 @ ??.???"; break; case 0x53: mode = "HDTV 768x576 @ ??.???"; gsSetVideoMode(GS_VideoMode::HDTV_576P); break;
case 0x54: mode = "HDTV 1920x1080 @ ??.???"; break; case 0x54: mode = "HDTV 1920x1080 @ ??.???"; gsSetVideoMode(GS_VideoMode::HDTV_1080P); break;
case 0x72: mode = "DVD NTSC 640x448 @ ??.???"; break; case 0x72: mode = "DVD NTSC 640x448 @ ??.???"; gsSetVideoMode(GS_VideoMode::BIOS); break;
case 0x73: mode = "DVD PAL/480P 720x480 @ ??.???"; break; case 0x73: mode = "DVD PAL 720x480 @ ??.???"; gsSetVideoMode(GS_VideoMode::BIOS); break;
default: Console.Error("Mode %x is not supported. Report me upstream", cpuRegs.GPR.n.a1.UC[0]); default:
DevCon.Error("Mode %x is not supported. Report me upstream", cpuRegs.GPR.n.a1.UC[0]);
gsSetVideoMode(GS_VideoMode::Unknown);
} }
Console.Warning("Set GS CRTC configuration. Interlace %s. Field Type %s. Mode %s", inter, field, mode.c_str()); DevCon.Warning("Set GS CRTC configuration. Interlace %s. Field Type %s. Mode %s", inter, field, mode.c_str());
} }
break; break;

View File

@ -591,8 +591,8 @@ void GSFrame::OnUpdateTitle( wxTimerEvent& evt )
AppConfig::UiTemplateOptions& templates = g_Conf->Templates; AppConfig::UiTemplateOptions& templates = g_Conf->Templates;
double fps = wxGetApp().FpsManager.GetFramerate(); double fps = wxGetApp().FpsManager.GetFramerate();
// The "not PAL" case covers both Region_NTSC and Region_NTSC_PROGRESSIVE // The "not PAL" case covers both NTSC and Progressive
float per = gsRegionMode == Region_PAL ? (fps * 100) / EmuConfig.GS.FrameratePAL.ToFloat() : (fps * 100) / EmuConfig.GS.FramerateNTSC.ToFloat(); float per = gsVideoMode == GS_VideoMode::PAL ? (fps * 100) / EmuConfig.GS.FrameratePAL.ToFloat() : (fps * 100) / EmuConfig.GS.FramerateNTSC.ToFloat();
char gsDest[128]; char gsDest[128];
gsDest[0] = 0; // No need to set whole array to NULL. gsDest[0] = 0; // No need to set whole array to NULL.