// File: /workspace/github_cpp_makefile_star2_O3/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movzbl (%rsi), %r14d
movb $0x1, 0x2c4(%rdi)
testl %edx, %edx
je 0x10383
movq %rdi, %rbx
testb %r14b, %r14b
leaq 0x1a6cc(%rip), %rsi     # 0x2a97a
leaq 0x1d65d(%rip), %r15     # 0x2d912
cmovnsq %r15, %rsi
leaq 0x1a69e(%rip), %rdi     # 0x2a95e
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
leaq 0x1a6da(%rip), %rsi     # 0x2a9ac
cmoveq %r15, %rsi
leaq 0x1a6b5(%rip), %rdi     # 0x2a992
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
jne 0x102fa
leaq 0x1b4c6(%rip), %rsi     # 0x2b7b7
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
testb %r14b, %r14b
js 0x1031c
movb 0x2c2(%rbx), %al
andb $0x30, %al
je 0x1031c
leaq 0x1a6b3(%rip), %rsi     # 0x2a9c3
movl $0x1, %edi
xorl %eax, %eax
callq 0x37cc
movl %r14d, %r15d
shrl $0x4, %r15d
andl $0x3, %r15d
movl %r14d, %r12d
shrl $0x2, %r12d
andl $0x3, %r12d
andl $0x3, %r14d
leaq 0x1a6c2(%rip), %rdi     # 0x2a9ff
xorl %eax, %eax
callq 0x3030
leaq 0x19b09(%rip), %rax     # 0x29e54
movslq (%rax,%r15,4), %rdi
addq %rax, %rdi
callq 0x3380
leaq 0x1a6b8(%rip), %rdi     # 0x2aa16
xorl %eax, %eax
callq 0x3030
leaq 0x16524(%rip), %rax     # 0x26890
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x1d59e(%rip), %rdi     # 0x2d91a
callq 0x3380
jmp 0x103f3
leaq 0x19dc5(%rip), %rsi     # 0x2a14f
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x37cc
leaq 0x1d5b4(%rip), %rdi     # 0x2d95b
callq 0x3380
cmpb $0x0, 0x2c2(%rbx)
js 0x10406
leaq 0x1a6e7(%rip), %rsi     # 0x2aaa3
xorl %edi, %edi
jmp 0x103ff
leaq 0x1d572(%rip), %rdi     # 0x2d939
callq 0x3380
jmp 0x10406
leaq 0x1d59a(%rip), %rdi     # 0x2d96f
callq 0x3380
cmpb $0x0, 0x2c2(%rbx)
jns 0x103f3
leaq 0x1a643(%rip), %rsi     # 0x2aa2d
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x1a71f(%rip), %rsi     # 0x2ab19
movl $0x1, %edi
xorl %eax, %eax
callq 0x37cc
leaq 0x1a743(%rip), %rdi     # 0x2ab50
xorl %eax, %eax
callq 0x3030
movl %r14d, %eax
leaq 0x16482(%rip), %rcx     # 0x268a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1d554(%rip), %rdi     # 0x2d982
callq 0x3380
leaq 0x1a72d(%rip), %rsi     # 0x2ab67
jmp 0x1046c
leaq 0x1d518(%rip), %rdi     # 0x2d95b
jmp 0x10455
leaq 0x1d4ed(%rip), %rdi     # 0x2d939
jmp 0x10455
leaq 0x1d51a(%rip), %rdi     # 0x2d96f
callq 0x3380
xorb %r15b, %r12b
xorb %r15b, %r14b
orb %r12b, %r14b
jne 0x10483
leaq 0x1a72d(%rip), %rsi     # 0x2ab99
movl $0x1, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x37cc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop