use the xrandr command in linux, this is the way of getting there.
xrandr is the tool that tells you at what connection andm ode your screen is running in all distro’s ive used. havent tried it at the Pi since its currently embedded in my casing.
Try typing xrandr and see if its a valid command.
then write a bash which evals xrandr outputs to true or false statements, and edit your retroarch.cfg to it with the update > retroarch.cfg command.