#!/bin/bash

modes="320x200 320x240 352x288 384x288 480x320 640x480 768x576 768x576 800x480 800x600 854x480
1024x576 1024x600 1024x768 1152x768 1152x864 1280x720 1280x768 1280x800 1280x854 1280x960 1280x1024
1366x768 1400x1050 1440x900 1440x960 1440x1080 1600x900 1600x1200 1680x1050 1920x1080 1920x1200
2048x1080 2048x1536 2560x1080 2560x1440 2560x1600 2560x2048 3840x2160 4096x2160"

echo "#"
echo "# This file is generated by 'modes.sh'."
echo "# All timings generated using 'cvt' from Xorg."
echo "#"
echo "# W  ......  Screen Width"
echo "# H  ......  Screen Height"
echo "# HFP  ....  Horizontal Front Porch"
echo "# HSYN  ...  Horizontal Sync Pulse"
echo "# HBP  ....  Horizontal Back Porch"
echo "# VFP  ....  Vertical Front Porch"
echo "# VSYN  ...  Vertical Sync Pulse"
echo "# VBP  ....  Vertical Back Porch"
echo "#"

printf '%-10s %5s %5s %4s %4s %4s %4s %4s %4s\n' "# MODE" W H HFP HSYN HBP VFP VSYN VBP
for r in $modes; do
	read w h < <( echo ${r/x/ } )
	read t1 t2 t3 x1 x2 x3 x4 y1 y2 y3 y4 t4 < <( cvt -v $w $h | grep -v '^#' )
	printf '%-10s %5d %5d %4d %4d %4d %4d %4d %4d\n' $r $w $h $((x2-x1)) $((x3-x2)) $((x4-x3)) $((y2-y1)) $((y3-y2)) $((y4-y3))
done | sort -n
for r in $modes; do
	read w h < <( echo ${r/x/ } )
	read t1 t2 t3 x1 x2 x3 x4 y1 y2 y3 y4 t4 < <( cvt -r -v $w $h | grep -v '^#' )
	printf '%-10s %5d %5d %4d %4d %4d %4d %4d %4d\n' ${r}R $w $h $((x2-x1)) $((x3-x2)) $((x4-x3)) $((y2-y1)) $((y3-y2)) $((y4-y3))
done | sort -n

# Small Resolution Testing Mode
printf '%-10s %5d %5d %4d %4d %4d %4d %4d %4d\n' 64x48T 64 48 2 4 2 1 2 1
