// File: /workspace/github_cpp_makefile_star2_O2/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 0xdc4b
movq %rdi, %rbx
testb %r14b, %r14b
leaq 0x16e02(%rip), %rsi     # 0x2497a
leaq 0x19d98(%rip), %r15     # 0x27917
cmovnsq %r15, %rsi
leaq 0x16dd4(%rip), %rdi     # 0x2495e
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
leaq 0x16e10(%rip), %rsi     # 0x249ac
cmoveq %r15, %rsi
leaq 0x16deb(%rip), %rdi     # 0x24992
xorl %eax, %eax
callq 0x3030
testb $0x40, %r14b
jne 0xdbc4
leaq 0x17bfc(%rip), %rsi     # 0x257b7
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
testb %r14b, %r14b
js 0xdbe4
movb 0x2c2(%rbx), %al
andb $0x30, %al
je 0xdbe4
leaq 0x16de9(%rip), %rsi     # 0x249c3
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x362c
movl %r14d, %r15d
shrl $0x4, %r15d
andl $0x3, %r15d
movl %r14d, %r12d
shrl $0x2, %r12d
andl $0x3, %r12d
andl $0x3, %r14d
leaq 0x16dfa(%rip), %rdi     # 0x249ff
xorl %eax, %eax
callq 0x3030
leaq 0x16241(%rip), %rax     # 0x23e54
movslq (%rax,%r15,4), %rdi
addq %rax, %rdi
callq 0x33b0
leaq 0x16df0(%rip), %rdi     # 0x24a16
xorl %eax, %eax
callq 0x3030
leaq 0x12c5c(%rip), %rax     # 0x20890
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x19cdb(%rip), %rdi     # 0x2791f
callq 0x33b0
jmp 0xdcbb
leaq 0x164fd(%rip), %rsi     # 0x2414f
xorl %edi, %edi
xorl %edx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x362c
leaq 0x19cf1(%rip), %rdi     # 0x27960
callq 0x33b0
cmpb $0x0, 0x2c2(%rbx)
js 0xdccc
leaq 0x16e1f(%rip), %rsi     # 0x24aa3
xorl %edi, %edi
jmp 0xdcc5
leaq 0x19caf(%rip), %rdi     # 0x2793e
callq 0x33b0
jmp 0xdccc
leaq 0x19cd7(%rip), %rdi     # 0x27974
callq 0x33b0
cmpb $0x0, 0x2c2(%rbx)
jns 0xdcbb
leaq 0x16d7b(%rip), %rsi     # 0x24a2d
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x16e57(%rip), %rsi     # 0x24b19
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x362c
leaq 0x16e7d(%rip), %rdi     # 0x24b50
xorl %eax, %eax
callq 0x3030
movl %r14d, %eax
leaq 0x12bbc(%rip), %rcx     # 0x208a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x19c93(%rip), %rdi     # 0x27987
callq 0x33b0
leaq 0x16e67(%rip), %rsi     # 0x24b67
jmp 0xdd32
leaq 0x19c57(%rip), %rdi     # 0x27960
jmp 0xdd1b
leaq 0x19c2c(%rip), %rdi     # 0x2793e
jmp 0xdd1b
leaq 0x19c59(%rip), %rdi     # 0x27974
callq 0x33b0
xorb %r15b, %r12b
xorb %r15b, %r14b
orb %r12b, %r14b
jne 0xdd47
leaq 0x16e67(%rip), %rsi     # 0x24b99
pushq $0x1
popq %rdi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x362c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
nop