// File: /workspace/github_cpp_makefile_star2_O1/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 0x10008
leaq 0x1a138(%rip), %rsi     # 0x2a127
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 0x37ec
movq %rsi, %rbx
movq %rdi, %r14
movzbl 0x3(%rsi), %r13d
shll $0x10, %r13d
movzbl 0x2(%rsi), %r12d
shll $0x8, %r12d
movzbl 0x1(%rsi), %r15d
movb (%rsi), %al
testb $0x20, %al
jne 0x1003e
cmpb $0x1, 0x2ce(%r14)
jne 0x1005e
leaq 0x1a611(%rip), %rsi     # 0x2a64d
jmp 0x10055
cmpb $0x1, 0x2ce(%r14)
jne 0x1004e
testb $0x20, %al
je 0x1002b
jmp 0x1005e
leaq 0x1a5b9(%rip), %rsi     # 0x2a60e
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
orl %r13d, %r12d
movzbl (%rbx), %eax
movl %eax, %esi
andl $0x1f, %esi
testb $0x40, %al
movq %r14, (%rsp)
jne 0x1009c
testl %esi, %esi
je 0x10085
leaq 0x1a628(%rip), %rsi     # 0x2a6a4
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
testb $0x20, (%rbx)
je 0x100ac
leaq 0x1a646(%rip), %rsi     # 0x2a6d7
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
jmp 0x100ac
incl %esi
leaq 0x1a5e8(%rip), %rdi     # 0x2a68d
xorl %eax, %eax
callq 0x3030
orl %r15d, %r12d
leaq 0x1d819(%rip), %rdi     # 0x2d8cf
callq 0x3380
leaq 0x29bae(%rip), %r13     # 0x39c70
leaq 0x1a634(%rip), %r15     # 0x2a6fd
xorl %r14d, %r14d
btl %r14d, %r12d
jae 0x100e0
movq (%r13), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x3030
incq %r14
addq $0x8, %r13
cmpq $0x15, %r14
jne 0x100cc
movb (%rbx), %al
andb $-0x60, %al
negb %al
jno 0x10105
leaq 0x1a60b(%rip), %rsi     # 0x2a707
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
movb $0x1, %al
movq (%rsp), %rcx
cmpb $0x0, 0x2cc(%rcx)
jne 0x10119
movb (%rbx), %al
shrb $0x7, %al
cmpl $0x7, %ebp
setb %cl
movl %eax, %edx
xorb $0x1, %dl
orb %cl, %dl
jne 0x10160
movzbl 0x4(%rbx), %esi
leaq 0x1a601(%rip), %rdi     # 0x2a734
xorl %eax, %eax
callq 0x3030
movzbl 0x5(%rbx), %esi
leaq 0x1a600(%rip), %rdi     # 0x2a745
xorl %eax, %eax
callq 0x3030
movzbl 0x6(%rbx), %esi
leaq 0x1a5ff(%rip), %rdi     # 0x2a756
xorl %eax, %eax
callq 0x3030
jmp 0x1017d
cmpl $0x7, %ebp
setb %cl
orb %al, %cl
jne 0x1017d
leaq 0x1a5f6(%rip), %rsi     # 0x2a767
movl $0x1, %edi
xorl %eax, %eax
callq 0x37ec
movb (%rbx), %al
testb $-0x80, %al
sete %cl
cmpl $0xa, %ebp
setb %dl
orb %cl, %dl
jne 0x101fc
movsbl 0x7(%rbx), %eax
cvtsi2sd %eax, %xmm0
mulsd 0x19d7a(%rip), %xmm0    # 0x29f18
leaq 0x1a621(%rip), %rdi     # 0x2a7c6
movb $0x1, %al
callq 0x3030
movsbl 0x8(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19d59(%rip), %xmm0    # 0x29f18
leaq 0x1a61b(%rip), %rdi     # 0x2a7e1
movb $0x1, %al
callq 0x3030
movsbl 0x9(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd 0x19d38(%rip), %xmm0    # 0x29f18
leaq 0x1a615(%rip), %rdi     # 0x2a7fc
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 0x1022a
leaq 0x1a607(%rip), %rsi     # 0x2a817
movl $0x1, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x37ec
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop