From f3be0c4a540ce4d3b80775851026accc483c2566 Mon Sep 17 00:00:00 2001 From: "Trevor Joynson (trevorj)" Date: Thu, 21 Dec 2017 23:25:14 -0800 Subject: [PATCH] Detect ratio of given mode to ensure it is supported --- 2880x1800.S | 2 +- 2880x1800.bin | Bin 128 -> 128 bytes modeline2edid | 67 +++++++++++++++++++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 18 deletions(-) diff --git a/2880x1800.S b/2880x1800.S index 6c85500..ebcc291 100644 --- a/2880x1800.S +++ b/2880x1800.S @@ -12,7 +12,7 @@ #define REVISION 3 #define XOFFSET 48 #define YOFFSET (63+3) -#define XY_RATIO XY_RATIO_16_9 +#define XY_RATIO XY_RATIO_16_10 #define YBLANK 52 #define XBLANK 160 #define TIMING_NAME "2880x1800" diff --git a/2880x1800.bin b/2880x1800.bin index 58b13d940ff7e1a8ccf167e98c35d455181e57cf..7d6b03c7510c70e6b5d67b84e492df898ae3df7b 100644 GIT binary patch delta 13 UcmZo*Y+#(A&d4xPBb+e-02fXJEC2ui delta 13 UcmZo*Y+#(A&Uj#=MmXaF02~ekEC2ui diff --git a/modeline2edid b/modeline2edid index 7cd10c8..6ef47d7 100755 --- a/modeline2edid +++ b/modeline2edid @@ -1,12 +1,33 @@ #!/bin/zsh emulate -L zsh +zmodload zsh/mathfunc setopt errexit errreturn #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() { [[ ${(L)1} = mode(|line) ]] || return 1 - echo "-- Found naughty unicorn: $@" + echo "-- Found modeline: $@" shift 1 local name="${1//\"}" @@ -21,7 +42,7 @@ template-S() { 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 edid_version="1.3" ratio="16:9" # TODO calc ratio + local edid_version="1.3" ratio="compute" local arg for arg in "$@"; do @@ -36,32 +57,44 @@ template-S() { esac 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 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%%.*}" REVISION "${edid_version#*.}" - CLOCK "$pixel_clock_khz" - XPIX "$hdisp" - YPIX "$vdisp" + 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" VFREQ "$vfreq_hz" - TIMING_NAME "${(qqq)name}" HSYNC_POL "$hsync_polarity" VSYNC_POL "$vsync_polarity" ) - local lines=('/* '"$name: $REPLY"' */') # removed -a option + local -a lines=('/* '"$name: $REPLY"' */') local k - for k in "${(@k)defines}"; do + for k in ${(k)defines}; do lines+=("#define $k ${defines[$k]}") - done lines+=('#include "edid.S"') @@ -75,7 +108,7 @@ local f=${1:-'-'} if [[ -z "$f" || "$f" == "-h" ]]; then self=${0:t} cat >&2 <<-EOF - Modeline2EDID, version forever 0.0.1 + ${0:t}, version forever 0.0.1 Help: $self -h Parse modelines from stdin: @@ -87,7 +120,7 @@ if [[ -z "$f" || "$f" == "-h" ]]; then exit 1 fi -echo "Searching for runaway unicorns in '$f'" +echo "Searching for modelines in '$f'" while read; do # trim REPLY=($=REPLY)