// File: /workspace/github_cpp_makefile_star2_O1/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::cta_vcdb(unsigned char const*, unsigned int)
void edid_state::cta_vcdb(const unsigned char *x, unsigned length)
{
	unsigned char d = x[0];

	cta.has_vcdb = true;
	if (length < 1) {
		fail("Empty Data Block with length %u.\n", length);
		return;
	}
	printf("    YCbCr quantization: %s\n",
	       (d & 0x80) ? "Selectable (via AVI YQ)" : "No Data");
	printf("    RGB quantization: %s\n",
	       (d & 0x40) ? "Selectable (via AVI Q)" : "No Data");
	/*
	 * If this bit is not set then that will result in interoperability
	 * problems (specifically with PCs/laptops) that quite often do not
	 * follow the default rules with respect to RGB Quantization Range
	 * handling.
	 *
	 * Starting with the CTA-861-H spec this bit is now required to be
	 * 1 for new designs.
	 */
	if (!(d & 0x40))
		fail("Set Selectable RGB Quantization to avoid interop issues.\n");
	/*
	 * Since most YCbCr formats use limited range, the interop issues are
	 * less noticable than for RGB formats.
	 *
	 * Starting with the CTA-861-H spec this bit is now required to be
	 * 1 for new designs, but just warn about it (for now).
	 */
	if ((cta.byte3 & 0x30) && !(d & 0x80))
		warn("Set Selectable YCbCr Quantization to avoid interop issues.\n");

	unsigned char s_pt = (d >> 4) & 0x03;
	unsigned char s_it = (d >> 2) & 0x03;
	unsigned char s_ce = d & 0x03;

	printf("    PT scan behavior: ");
	switch (s_pt) {
	case 0: printf("No Data\n"); break;
	case 1: printf("Always Overscanned\n"); break;
	case 2: printf("Always Underscanned\n"); break;
	case 3: printf("Supports both over- and underscan\n"); break;
	}
	printf("    IT scan behavior: ");
	switch (s_it) {
	case 0: printf("IT video formats not supported\n"); break;
	case 1:
		printf("Always Overscanned\n");
		// See Table 52 of CTA-861-G for a description of Byte 3
		if (cta.byte3 & 0x80)
			fail("IT video formats are always overscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to underscanned.\n");
		break;
	case 2:
		printf("Always Underscanned\n");
		// See Table 52 of CTA-861-G for a description of Byte 3
		if (!(cta.byte3 & 0x80))
			fail("IT video formats are always underscanned, but bit 7 of Byte 3 of the CTA-861 Extension header is set to overscanned.\n");
		break;
	case 3: printf("Supports both over- and underscan\n"); break;
	}
	if (s_it < 2)
		warn("IT scan behavior is expected to support underscanned.\n");
	printf("    CE scan behavior: ");
	switch (s_ce) {
	case 0: printf("CE video formats not supported\n"); break;
	case 1: printf("Always Overscanned\n"); break;
	case 2: printf("Always Underscanned\n"); break;
	case 3: printf("Supports both over- and underscan\n"); break;
	}
	if (s_ce == 0)
		warn("'CE video formats not supported' makes no sense.\n");
	else if (s_pt == s_it && s_pt == s_ce)
		warn("S_PT is equal to S_IT and S_CE, so should be set to 0 instead.\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movzbl (%rsi), %r14d
movb $0x1, 0x2c4(%rdi)
testl %edx, %edx
je 0x1052d
movq %rdi, %rbx
testb %r14b, %r14b
leaq 0x1a4f9(%rip), %rsi     # 0x2a952
leaq 0x1d48a(%rip), %r15     # 0x2d8ea
cmovnsq %r15, %rsi
leaq 0x1a4cb(%rip), %rdi     # 0x2a936
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
leaq 0x1a507(%rip), %rsi     # 0x2a984
cmoveq %r15, %rsi
leaq 0x1a4e2(%rip), %rdi     # 0x2a96a
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
jne 0x104a5
leaq 0x1b2f3(%rip), %rsi     # 0x2b78f
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
testb %r14b, %r14b
js 0x104c7
movb 0x2c2(%rbx), %al
andb $0x30, %al
je 0x104c7
leaq 0x1a4e0(%rip), %rsi     # 0x2a99b
movl $0x1, %edi
xorl %eax, %eax
callq 0x37ec
movl %r14d, %r15d
shrl $0x4, %r15d
andl $0x3, %r15d
movl %r14d, %ebp
shrb $0x2, %bpl
andb $0x3, %bpl
andl $0x3, %r14d
leaq 0x1a4ef(%rip), %rdi     # 0x2a9d7
xorl %eax, %eax
callq 0x3030
leaq 0x19926(%rip), %rax     # 0x29e1c
movslq (%rax,%r15,4), %rdi
addq %rax, %rdi
callq 0x3380
leaq 0x1a4e5(%rip), %rdi     # 0x2a9ee
xorl %eax, %eax
callq 0x3030
movzbl %bpl, %eax
leaq 0x1635d(%rip), %rcx     # 0x26878
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1d3c7(%rip), %rdi     # 0x2d8f2
jmp 0x1056e
leaq 0x19bf3(%rip), %rsi     # 0x2a127
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37ec
leaq 0x1d3e3(%rip), %rdi     # 0x2d933
callq 0x3380
cmpb $0x0, 0x2c2(%rbx)
js 0x1059a
leaq 0x1a516(%rip), %rsi     # 0x2aa7b
jmp 0x10591
leaq 0x1d3a3(%rip), %rdi     # 0x2d911
callq 0x3380
jmp 0x1059a
leaq 0x1d3cb(%rip), %rdi     # 0x2d947
callq 0x3380
cmpb $0x0, 0x2c2(%rbx)
jns 0x1059a
leaq 0x1a474(%rip), %rsi     # 0x2aa05
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
cmpb $0x1, %bpl
ja 0x105b3
leaq 0x1a54a(%rip), %rsi     # 0x2aaf1
movl $0x1, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x1a56e(%rip), %rdi     # 0x2ab28
xorl %eax, %eax
callq 0x3030
leaq 0x19864(%rip), %rax     # 0x29e2c
movslq (%rax,%r14,4), %rdi
addq %rax, %rdi
callq 0x3380
testb %r14b, %r14b
je 0x105ed
xorb %r15b, %bpl
xorb %r15b, %r14b
orb %bpl, %r14b
jne 0x1060a
leaq 0x1a586(%rip), %rsi     # 0x2ab71
jmp 0x105f4
leaq 0x1a54b(%rip), %rsi     # 0x2ab3f
movl $0x1, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37ec
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop