Detect ratio of given mode to ensure it is supported

This commit is contained in:
Trevor Joynson (trevorj)
2017-12-21 23:25:14 -08:00
parent 6cf3382311
commit f3be0c4a54
3 changed files with 51 additions and 18 deletions

View File

@@ -12,7 +12,7 @@
#define REVISION 3 #define REVISION 3
#define XOFFSET 48 #define XOFFSET 48
#define YOFFSET (63+3) #define YOFFSET (63+3)
#define XY_RATIO XY_RATIO_16_9 #define XY_RATIO XY_RATIO_16_10
#define YBLANK 52 #define YBLANK 52
#define XBLANK 160 #define XBLANK 160
#define TIMING_NAME "2880x1800" #define TIMING_NAME "2880x1800"

Binary file not shown.

View File

@@ -1,12 +1,33 @@
#!/bin/zsh #!/bin/zsh
emulate -L zsh emulate -L zsh
zmodload zsh/mathfunc
setopt errexit errreturn setopt errexit errreturn
#setopt xtrace #setopt xtrace
find-supported-ratio() {
local x=$1 y=$2 default=$3; shift 3
[ $# -gt 0 ] || set -- 16:10 16:9 4:3 5:4 # supported already in edid.S
local -A vals=()
local r
for r in "$@"; do
local -i rx=${r%%:*} ry=${r#*:}
local v=$(( abs( $x / $rx - $y / $ry ) ))
vals[$v]=$r
done
local best=${vals[0]}
[[ -n $best ]] || best=$default
echo $best
}
template-S() { template-S() {
[[ ${(L)1} = mode(|line) ]] || return 1 [[ ${(L)1} = mode(|line) ]] || return 1
echo "-- Found naughty unicorn: $@" echo "-- Found modeline: $@"
shift 1 shift 1
local name="${1//\"}" local name="${1//\"}"
@@ -21,7 +42,7 @@ template-S() {
local -i vdisp="$1" vsyncstart="$2" vsyncend="$3" vtotal="$4"; shift 4 local -i vdisp="$1" vsyncstart="$2" vsyncend="$3" vtotal="$4"; shift 4
local -i hsync_polarity=0 vsync_polarity=0 dpi=96 vfreq_hz=60 local -i hsync_polarity=0 vsync_polarity=0 dpi=96 vfreq_hz=60
local edid_version="1.3" ratio="16:9" # TODO calc ratio local edid_version="1.3" ratio="compute"
local arg local arg
for arg in "$@"; do for arg in "$@"; do
@@ -36,32 +57,44 @@ template-S() {
esac esac
done done
case $ratio in
compute)
# 16:9 is the default here if it can't find one that matches nicely.
ratio=$(find-supported-ratio $hdisp $vdisp 'ERROR')
printf 'Computed ratio: %s' $ratio
[[ $ratio != 'ERROR' ]] || return 1
;;
esac
local -A defines local -A defines
defines=( defines=(
TIMING_NAME "${(qqq)name}"
CLOCK "$pixel_clock_khz"
XPIX "$hdisp"
XBLANK "$((htotal - hdisp))"
XOFFSET "$((hsyncstart - hdisp))"
XPULSE "$((hsyncend - hsyncstart))"
YPIX "$vdisp"
YBLANK "$((vtotal - vdisp))"
YOFFSET "(63+$((vsyncstart - vdisp)))"
YPULSE "(63+$((vsyncend - vsyncstart)))"
VERSION "${edid_version%%.*}" VERSION "${edid_version%%.*}"
REVISION "${edid_version#*.}" REVISION "${edid_version#*.}"
CLOCK "$pixel_clock_khz"
XPIX "$hdisp"
YPIX "$vdisp"
XY_RATIO "XY_RATIO_${(U)ratio//:/_}" XY_RATIO "XY_RATIO_${(U)ratio//:/_}"
XBLANK "$((htotal - hdisp))"
YBLANK "$((vtotal - vdisp))"
XOFFSET "$((hsyncstart - hdisp))"
XPULSE "$((hsyncend - hsyncstart))"
YOFFSET "(63+$((vsyncstart - vdisp)))"
YPULSE "(63+$((vsyncend - vsyncstart)))"
DPI "$dpi" DPI "$dpi"
VFREQ "$vfreq_hz" VFREQ "$vfreq_hz"
TIMING_NAME "${(qqq)name}"
HSYNC_POL "$hsync_polarity" HSYNC_POL "$hsync_polarity"
VSYNC_POL "$vsync_polarity" VSYNC_POL "$vsync_polarity"
) )
local lines=('/* '"$name: $REPLY"' */') # removed -a option local -a lines=('/* '"$name: $REPLY"' */')
local k local k
for k in "${(@k)defines}"; do for k in ${(k)defines}; do
lines+=("#define $k ${defines[$k]}") lines+=("#define $k ${defines[$k]}")
done done
lines+=('#include "edid.S"') lines+=('#include "edid.S"')
@@ -75,7 +108,7 @@ local f=${1:-'-'}
if [[ -z "$f" || "$f" == "-h" ]]; then if [[ -z "$f" || "$f" == "-h" ]]; then
self=${0:t} self=${0:t}
cat >&2 <<-EOF cat >&2 <<-EOF
Modeline2EDID, version forever 0.0.1 ${0:t}, version forever 0.0.1
Help: Help:
$self -h $self -h
Parse modelines from stdin: Parse modelines from stdin:
@@ -87,7 +120,7 @@ if [[ -z "$f" || "$f" == "-h" ]]; then
exit 1 exit 1
fi fi
echo "Searching for runaway unicorns in '$f'" echo "Searching for modelines in '$f'"
while read; do while read; do
# trim # trim
REPLY=($=REPLY) REPLY=($=REPLY)