Script to change resolution for CRT TV

Hi guys!

I have installed CRT emudriver on a windows 10 PC with an AMD r7 260X. I run a VGA-cable to an UMSA-converter and SCART to my B&O MX4000 consumer CRT. It’s a european model that does both 50 and 60 hz.

I use Retroarch 1.90 with switchres. The later versions have been giving me trouble with audio crackles.

Some times when I have been running a game in a 240p resolution in Retroarch, the resolution doesn’t change back to 480i (my desktop resolution) after I quit Retroarch. This happens especially often with the Mupen64-next core.

To solve this I’m trying to use an AHK-script to easily change the resolution back to 480i. However, it’s behaving strangely. When I run it while in 768x576 (PAL-resolution) or in 320x240, it changes to 640x480 with no trouble. But when I run it in while in a super resolution, like 2560x240, nothing happens.

My AHK-script looks like this:

r::
ChangeResolution(32,640,480,60)
return

ChangeResolution( cD, sW, sH, rR )
{
	VarSetCapacity(dM,156,0), NumPut(156,2,&dM,36)
	DllCall( "EnumDisplaySettingsA", UInt,0, UInt,-1, UInt,&dM ),
	NumPut(0x5c0000,dM,40)
	NumPut(cD,dM,104), NumPut(sW,dM,108), NumPut(sH,dM,112), NumPut(rR,dM,120)
	Return DllCall( "ChangeDisplaySettingsA", UInt,&dM, UInt,0 )
}

My resolutions for CRT emudriver look like this:

## Desktop ##

 320 x 240 @ 60.000000 desktop
 640 x 480 @ 60.000000 desktop
 768 x 576 @ 50.000000 desktop

## Super resolutions ##

2560 x 240 @ 60.000000 super
2560 x 248 @ 60.000000 super
2560 x 256 @ 60.000000 super
2560 x 264 @ 60.000000 super
2560 x 272 @ 60.000000 super
2560 x 280 @ 60.000000 super
2560 x 288 @ 60.000000 super
2560 x 296 @ 60.000000 super
2560 x 304 @ 60.000000 super
2560 x 320 @ 60.000000 super
2560 x 336 @ 60.000000 super
2560 x 344 @ 60.000000 super
2560 x 352 @ 60.000000 super
2560 x 360 @ 60.000000 super
2560 x 368 @ 60.000000 super
2560 x 376 @ 60.000000 super
2560 x 384 @ 60.000000 super
2560 x 392 @ 60.000000 super
2560 x 400 @ 60.000000 super
2560 x 416 @ 60.000000 super
2560 x 432 @ 60.000000 super
2560 x 448 @ 60.000000 super
2560 x 464 @ 60.000000 super
2560 x 480 @ 60.000000 super
2560 x 496 @ 60.000000 super
2560 x 512 @ 59.000000 super
2560 x 544 @ 55.000000 super
2560 x 560 @ 54.000000 super
2560 x 768 @ 60.000000 super
2560 x 800 @ 60.000000 super
2560 x 192 @ 60.000000 retroarch
2560 x 200 @ 60.000000 retroarch
2560 x 240 @ 60.000000 retroarch
2560 x 224 @ 60.000000 retroarch
2560 x 237 @ 60.000000 retroarch
2560 x 256 @ 50.000000 retroarch
2560 x 254 @ 55.000000 retroarch
2560 x 448 @ 60.000000 retroarch
2560 x 480 @ 60.000000 retroarch
2560 x 192 @ 50.000000 retroarch
2560 x 200 @ 50.000000 retroarch
2560 x 240 @ 50.000000 retroarch
2560 x 224 @ 50.000000 retroarch
2560 x 288 @ 50.000000 retroarch
2560 x 237 @ 50.000000 retroarch
2560 x 254 @ 50.000000 retroarch
2560 x 448 @ 50.000000 retroarch
2560 x 480 @ 50.000000 retroarch
2560 x 512 @ 50.000000 retroarch
2560 x 576 @ 50.000000 retroarch

Any idea how I can get the script to change the resolution back to 480i from a 240p super resolution? Switching manually works, so it should be possible!

Thanks in advance!