// File: rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::check_cta_blocks()
void edid_state::check_cta_blocks()
{
	unsigned max_pref_prog_hact = 0;
	unsigned max_pref_prog_vact = 0;
	unsigned max_pref_ilace_hact = 0;
	unsigned max_pref_ilace_vact = 0;

	data_block = "CTA-861";
	for (vec_timings_ext::iterator iter = cta.preferred_timings.begin();
	     iter != cta.preferred_timings.end(); ++iter) {
		if (iter->t.interlaced &&
		    (iter->t.vact > max_pref_ilace_vact ||
		     (iter->t.vact == max_pref_ilace_vact && iter->t.hact >= max_pref_ilace_hact))) {
			max_pref_ilace_hact = iter->t.hact;
			max_pref_ilace_vact = iter->t.vact;
		}
		if (!iter->t.interlaced &&
		    (iter->t.vact > max_pref_prog_vact ||
		     (iter->t.vact == max_pref_prog_vact && iter->t.hact >= max_pref_prog_hact))) {
			max_pref_prog_hact = iter->t.hact;
			max_pref_prog_vact = iter->t.vact;
		}
	}

	unsigned native_prog = 0;
	unsigned native_prog_hact = 0;
	unsigned native_prog_vact = 0;
	bool native_prog_mixed_resolutions = false;
	unsigned native_ilace = 0;
	unsigned native_ilace_hact = 0;
	unsigned native_ilace_vact = 0;
	bool native_ilace_mixed_resolutions = false;

	for (vec_timings_ext::iterator iter = cta.native_timings.begin();
	     iter != cta.native_timings.end(); ++iter) {
		if (iter->t.interlaced) {
			native_ilace++;
			if (!native_ilace_hact) {
				native_ilace_hact = iter->t.hact;
				native_ilace_vact = iter->t.vact;
			} else if (native_ilace_hact != iter->t.hact ||
				   native_ilace_vact != iter->t.vact) {
				native_ilace_mixed_resolutions = true;
			}
		} else {
			native_prog++;
			if (!native_prog_hact) {
				native_prog_hact = iter->t.hact;
				native_prog_vact = iter->t.vact;
			} else if (native_prog_hact != iter->t.hact ||
				   native_prog_vact != iter->t.vact) {
				native_prog_mixed_resolutions = true;
			}
		}
	}

	if (native_prog_mixed_resolutions)
		fail("Native progressive timings are a mix of several resolutions.\n");
	if (native_ilace_mixed_resolutions)
		fail("Native interlaced timings are a mix of several resolutions.\n");
	if (native_ilace && !native_prog)
		fail("A native interlaced timing is present, but not a native progressive timing.\n");
	if (!native_prog_mixed_resolutions && native_prog > 1)
		warn("Multiple native progressive timings are defined.\n");
	if (!native_ilace_mixed_resolutions && native_ilace > 1)
		warn("Multiple native interlaced timings are defined.\n");

	if (!native_prog_mixed_resolutions && native_prog_vact &&
	    (max_pref_prog_vact > native_prog_vact ||
	     (max_pref_prog_vact == native_prog_vact && max_pref_prog_hact > native_prog_hact)))
		warn("Native progressive resolution of %ux%u is smaller than the max preferred progressive resolution %ux%u.\n",
		     native_prog_hact, native_prog_vact,
		     max_pref_prog_hact, max_pref_prog_vact);
	if (!native_ilace_mixed_resolutions && native_ilace_vact &&
	    (max_pref_ilace_vact > native_ilace_vact ||
	     (max_pref_ilace_vact == native_ilace_vact && max_pref_ilace_hact > native_ilace_hact)))
		warn("Native interlaced resolution of %ux%u is smaller than the max preferred interlaced resolution %ux%u.\n",
		     native_ilace_hact, native_ilace_vact,
		     max_pref_ilace_hact, max_pref_ilace_vact);

	if (dispid.native_width && native_prog_hact &&
	    !native_prog_mixed_resolutions) {
		if (dispid.native_width != native_prog_hact ||
		    dispid.native_height != native_prog_vact)
			fail("Mismatch between CTA-861 and DisplayID native progressive resolution.\n");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
addq $0x30, %rdi
leaq 0x1c17e(%rip), %rsi     # 0x3a7b9
callq 0x4420
movq -0x60(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xb9a0
movq %rax, -0x20(%rbp)
movq -0x60(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x40, %rdi
callq 0xba10
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb9d0
testb $0x1, %al
jne 0x1e686
jmp 0x1e752
leaq -0x20(%rbp), %rdi
callq 0x20320
testb $0x1, 0x18(%rax)
je 0x1e6e4
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
ja 0x1e6c7
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
cmpl -0x18(%rbp), %eax
jne 0x1e6e4
leaq -0x20(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jb 0x1e6e4
leaq -0x20(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
movl %eax, -0x14(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x20320
testb $0x1, 0x18(%rax)
jne 0x1e742
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
cmpl -0x10(%rbp), %eax
ja 0x1e725
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
cmpl -0x10(%rbp), %eax
jne 0x1e742
leaq -0x20(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jb 0x1e742
leaq -0x20(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
movl %eax, -0xc(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
movl %eax, -0x10(%rbp)
jmp 0x1e744
leaq -0x20(%rbp), %rdi
callq 0xba60
jmp 0x1e658
movq -0x60(%rbp), %rdi
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movb $0x0, -0x35(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movb $0x0, -0x45(%rbp)
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xb9a0
movq %rax, -0x50(%rbp)
movq -0x60(%rbp), %rdi
addq $0x180, %rdi            # imm = 0x180
addq $0x128, %rdi            # imm = 0x128
callq 0xba10
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0xb9d0
testb $0x1, %al
jne 0x1e7d0
jmp 0x1e8c1
leaq -0x50(%rbp), %rdi
callq 0x20320
testb $0x1, 0x18(%rax)
je 0x1e848
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x1e80d
leaq -0x50(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
movl %eax, -0x40(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x1e846
movl -0x40(%rbp), %eax
movl %eax, -0x64(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movq %rax, %rcx
movl -0x64(%rbp), %eax
cmpl (%rcx), %eax
jne 0x1e840
movl -0x44(%rbp), %eax
movl %eax, -0x68(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movq %rax, %rcx
movl -0x68(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0x1e844
movb $0x1, -0x45(%rbp)
jmp 0x1e846
jmp 0x1e8b1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x30(%rbp)
jne 0x1e876
leaq -0x50(%rbp), %rdi
callq 0x20320
movl (%rax), %eax
movl %eax, -0x30(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0x1e8af
movl -0x30(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movq %rax, %rcx
movl -0x6c(%rbp), %eax
cmpl (%rcx), %eax
jne 0x1e8a9
movl -0x34(%rbp), %eax
movl %eax, -0x70(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20320
movq %rax, %rcx
movl -0x70(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0x1e8ad
movb $0x1, -0x35(%rbp)
jmp 0x1e8af
jmp 0x1e8b1
jmp 0x1e8b3
leaq -0x50(%rbp), %rdi
callq 0xba60
jmp 0x1e79f
testb $0x1, -0x35(%rbp)
je 0x1e8d7
xorl %edi, %edi
leaq 0x1c860(%rip), %rsi     # 0x3b130
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x45(%rbp)
je 0x1e8ed
xorl %edi, %edi
leaq 0x1c888(%rip), %rsi     # 0x3b16e
movb $0x0, %al
callq 0x47d0
cmpl $0x0, -0x3c(%rbp)
je 0x1e909
cmpl $0x0, -0x2c(%rbp)
jne 0x1e909
xorl %edi, %edi
leaq 0x1c8a9(%rip), %rsi     # 0x3b1ab
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x35(%rbp)
jne 0x1e928
cmpl $0x1, -0x2c(%rbp)
jbe 0x1e928
movl $0x1, %edi
leaq 0x1c8d7(%rip), %rsi     # 0x3b1f8
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x45(%rbp)
jne 0x1e947
cmpl $0x1, -0x3c(%rbp)
jbe 0x1e947
movl $0x1, %edi
leaq 0x1c8ea(%rip), %rsi     # 0x3b22a
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x35(%rbp)
jne 0x1e98c
cmpl $0x0, -0x34(%rbp)
je 0x1e98c
movl -0x10(%rbp), %eax
cmpl -0x34(%rbp), %eax
ja 0x1e96b
movl -0x10(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x1e98c
movl -0xc(%rbp), %eax
cmpl -0x30(%rbp), %eax
jbe 0x1e98c
movl -0x30(%rbp), %edx
movl -0x34(%rbp), %ecx
movl -0xc(%rbp), %r8d
movl -0x10(%rbp), %r9d
movl $0x1, %edi
leaq 0x1c8d6(%rip), %rsi     # 0x3b25b
movb $0x0, %al
callq 0x47d0
testb $0x1, -0x45(%rbp)
jne 0x1e9d1
cmpl $0x0, -0x44(%rbp)
je 0x1e9d1
movl -0x18(%rbp), %eax
cmpl -0x44(%rbp), %eax
ja 0x1e9b0
movl -0x18(%rbp), %eax
cmpl -0x44(%rbp), %eax
jne 0x1e9d1
movl -0x14(%rbp), %eax
cmpl -0x40(%rbp), %eax
jbe 0x1e9d1
movl -0x40(%rbp), %edx
movl -0x44(%rbp), %ecx
movl -0x14(%rbp), %r8d
movl -0x18(%rbp), %r9d
movl $0x1, %edi
leaq 0x1c8f9(%rip), %rsi     # 0x3b2c3
movb $0x0, %al
callq 0x47d0
movq -0x60(%rbp), %rax
cmpl $0x0, 0x940(%rax)
je 0x1ea1a
cmpl $0x0, -0x30(%rbp)
je 0x1ea1a
testb $0x1, -0x35(%rbp)
jne 0x1ea1a
movq -0x60(%rbp), %rax
movl 0x940(%rax), %eax
cmpl -0x30(%rbp), %eax
jne 0x1ea08
movq -0x60(%rbp), %rax
movl 0x944(%rax), %eax
cmpl -0x34(%rbp), %eax
je 0x1ea18
xorl %edi, %edi
leaq 0x1c918(%rip), %rsi     # 0x3b329
movb $0x0, %al
callq 0x47d0
jmp 0x1ea1a
addq $0x70, %rsp
popq %rbp
retq