// File: /workspace/github_cpp_makefile_star2_O3/rpavlik[P]edid-decode/parse-cta-block.cpp
// Function: edid_state::cta_rcdb(unsigned char const*, unsigned int)
void edid_state::cta_rcdb(const unsigned char *x, unsigned length)
{
	unsigned spm = ((x[3] << 16) | (x[2] << 8) | x[1]);
	unsigned i;

	if (length < 4) {
		fail("Empty Data Block with length %u.\n", length);
		return;
	}

	if ((x[0] & 0x20) && !cta.has_sldb)
		fail("'SLD' flag is 1, but no Speaker Location Data Block is found.\n");
	else if (!(x[0] & 0x20) && cta.has_sldb)
		fail("'SLD' flag is 0, but a Speaker Location Data Block is present.\n");

	if (x[0] & 0x40) {
		printf("    Speaker count: %u\n", (x[0] & 0x1f) + 1);
	} else {
		if (x[0] & 0x1f)
			fail("'Speaker' flag is 0, but 'Speaker Count' is != 0.\n");
		if (x[0] & 0x20)
			fail("'SLD' flag is 1, but 'Speaker' is 0.\n");
	}

	printf("    Speaker Presence Mask:\n");
	for (i = 0; i < ARRAY_SIZE(speaker_map); i++) {
		if ((spm >> i) & 1)
			printf("      %s\n", speaker_map[i]);
	}

	if ((x[0] & 0xa0) == 0x80)
		fail("'Display' flag set, but not the 'SLD' flag.\n");

	bool valid_max = cta.preparsed_sld_has_coord || (x[0] & 0x80);

	if (valid_max && length >= 7) {
		printf("    Xmax: %u dm\n", x[4]);
		printf("    Ymax: %u dm\n", x[5]);
		printf("    Zmax: %u dm\n", x[6]);
	} else if (!valid_max && length >= 7) {
		// The RCDB should have been truncated.
		warn("'Display' flag is 0 and 'Coord' is 0 for all SLDs, but the Max coordinates are still present.\n");
	}
	if ((x[0] & 0x80) && length >= 10) {
		printf("    DisplayX: %.3f * Xmax\n", decode_uchar_as_double(x[7]));
		printf("    DisplayY: %.3f * Ymax\n", decode_uchar_as_double(x[8]));
		printf("    DisplayZ: %.3f * Zmax\n", decode_uchar_as_double(x[9]));
	} else if (!(x[0] & 0x80) && length >= 10) {
		// The RCDB should have been truncated.
		warn("'Display' flag is 0, but the Display coordinates are still present.\n");
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
cmpl $0x3, %edx
ja 0xfe76
leaq 0x1a2f2(%rip), %rsi     # 0x2a14f
xorl %edi, %edi
movl %ebp, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x37cc
movq %rsi, %rbx
movzwl 0x2(%rsi), %r12d
movzbl 0x1(%rsi), %r15d
testb $0x20, (%rsi)
movq %rdi, (%rsp)
movb 0x2ce(%rdi), %al
jne 0xfe9f
testb %al, %al
je 0xfeb3
leaq 0x1a7d8(%rip), %rsi     # 0x2a675
jmp 0xfeaa
testb %al, %al
jne 0xfeb3
leaq 0x1a78c(%rip), %rsi     # 0x2a636
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
shll $0x8, %r12d
movzbl (%rbx), %eax
movl %eax, %esi
andl $0x1f, %esi
testb $0x40, %al
jne 0xfeef
testl %esi, %esi
je 0xfed9
leaq 0x1a7fe(%rip), %rsi     # 0x2a6cc
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
movb (%rbx), %al
testb $0x20, %al
je 0xfeff
leaq 0x1a81b(%rip), %rsi     # 0x2a6ff
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
jmp 0xfeff
incl %esi
leaq 0x1a7bd(%rip), %rdi     # 0x2a6b5
xorl %eax, %eax
callq 0x3030
orl %r15d, %r12d
leaq 0x1d9ee(%rip), %rdi     # 0x2d8f7
callq 0x3380
leaq 0x29d5b(%rip), %r13     # 0x39c70
leaq 0x1a809(%rip), %r15     # 0x2a725
xorl %r14d, %r14d
btl %r14d, %r12d
jae 0xff33
movq (%r13), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x3030
incq %r14
addq $0x8, %r13
cmpq $0x15, %r14
jne 0xff1f
movb (%rbx), %al
andb $-0x60, %al
negb %al
jno 0xff58
leaq 0x1a7e0(%rip), %rsi     # 0x2a72f
xorl %edi, %edi
xorl %eax, %eax
callq 0x37cc
movb $0x1, %al
movq (%rsp), %rcx
cmpb $0x0, 0x2cc(%rcx)
jne 0xff6c
movb (%rbx), %al
shrb $0x7, %al
cmpl $0x7, %ebp
setb %cl
movl %eax, %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0xffb3
movzbl 0x4(%rbx), %esi
leaq 0x1a7d6(%rip), %rdi     # 0x2a75c
xorl %eax, %eax
callq 0x3030
movzbl 0x5(%rbx), %esi
leaq 0x1a7d5(%rip), %rdi     # 0x2a76d
xorl %eax, %eax
callq 0x3030
movzbl 0x6(%rbx), %esi
leaq 0x1a7d4(%rip), %rdi     # 0x2a77e
xorl %eax, %eax
callq 0x3030
jmp 0xffd0
cmpl $0x7, %ebp
setb %cl
orb %al, %cl
jne 0xffd0
leaq 0x1a7cb(%rip), %rsi     # 0x2a78f
movl $0x1, %edi
xorl %eax, %eax
callq 0x37cc
movb (%rbx), %al
testb $-0x80, %al
sete %cl
cmpl $0xa, %ebp
setb %dl
orb %cl, %dl
jne 0x1004f
movsbl 0x7(%rbx), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x19f4f(%rip), %xmm0    # 0x29f40
leaq 0x1a7f6(%rip), %rdi     # 0x2a7ee
movb $0x1, %al
callq 0x3030
movsbl 0x8(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19f2e(%rip), %xmm0    # 0x29f40
leaq 0x1a7f0(%rip), %rdi     # 0x2a809
movb $0x1, %al
callq 0x3030
movsbl 0x9(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19f0d(%rip), %xmm0    # 0x29f40
leaq 0x1a7ea(%rip), %rdi     # 0x2a824
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3030
cmpl $0xa, %ebp
setb %cl
shrb $0x7, %al
orb %cl, %al
jne 0x1007d
leaq 0x1a7dc(%rip), %rsi     # 0x2a83f
movl $0x1, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x37cc
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq