// File: rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_parameters_v2(unsigned char const*, unsigned int)
void edid_state::parse_displayid_parameters_v2(const unsigned char *x,
					       unsigned block_rev)
{
	if (!check_displayid_datablock_length(x, 29, 29))
		return;

	unsigned hor_size = (x[4] << 8) + x[3];
	unsigned vert_size = (x[6] << 8) + x[5];

	dispid.has_display_parameters = true;
	if (x[1] & 0x80)
		printf("    Image size: %u mm x %u mm\n",
		       hor_size, vert_size);
	else
		printf("    Image size: %.1f mm x %.1f mm\n",
		       hor_size / 10.0, vert_size / 10.0);
	unsigned w = (x[8] << 8) + x[7];
	unsigned h = (x[10] << 8) + x[9];
	if (w && h) {
		printf("    Native Format: %ux%u\n", w, h);
		dispid.native_width = w;
		dispid.native_height = h;
	} else if (w || h) {
		fail("Invalid Native Format %ux%u.\n", w, h);
	}
	unsigned char v = x[11];
	printf("    Scan Orientation: ");
	switch (v & 0x07) {
	case 0x00: printf("Left to Right, Top to Bottom\n"); break;
	case 0x01: printf("Right to Left, Top to Bottom\n"); break;
	case 0x02: printf("Top to Bottom, Right to Left\n"); break;
	case 0x03: printf("Bottom to Top, Right to Left\n"); break;
	case 0x04: printf("Right to Left, Bottom to Top\n"); break;
	case 0x05: printf("Left to Right, Bottom to Top\n"); break;
	case 0x06: printf("Bottom to Top, Left to Right\n"); break;
	case 0x07: printf("Top to Bottom, Left to Right\n"); break;
	}
	printf("    Luminance Information: ");
	switch ((v >> 3) & 0x03) {
	case 0x00: printf("Minimum guaranteed value\n"); break;
	case 0x01: printf("Guidance for the Source device\n"); break;
	default: printf("Reserved\n"); break;
	}
	printf("    Color Information: CIE %u\n",
	       (v & 0x40) ? 1976 : 1931);
	printf("    Audio Speaker Information: %sintegrated\n",
	       (v & 0x80) ? "not " : "");
	printf("    Native Color Chromaticity:\n");
	printf("      Primary #1:  (%.6f, %.6f)\n",
	       fp2d(x[0x0c] | ((x[0x0d] & 0x0f) << 8)),
	       fp2d(((x[0x0d] & 0xf0) >> 4) | (x[0x0e] << 4)));
	printf("      Primary #2:  (%.6f, %.6f)\n",
	       fp2d(x[0x0f] | ((x[0x10] & 0x0f) << 8)),
	       fp2d(((x[0x10] & 0xf0) >> 4) | (x[0x11] << 4)));
	printf("      Primary #3:  (%.6f, %.6f)\n",
	       fp2d(x[0x12] | ((x[0x13] & 0x0f) << 8)),
	       fp2d(((x[0x13] & 0xf0) >> 4) | (x[0x14] << 4)));
	printf("      White Point: (%.6f, %.6f)\n",
	       fp2d(x[0x15] | ((x[0x16] & 0x0f) << 8)),
	       fp2d(((x[0x16] & 0xf0) >> 4) | (x[0x17] << 4)));
	printf("    Native Maximum Luminance (Full Coverage): %s\n",
	       ieee7542d(x[0x18] | (x[0x19] << 8)).c_str());
	printf("    Native Maximum Luminance (10%% Rectangular Coverage): %s\n",
	       ieee7542d(x[0x1a] | (x[0x1b] << 8)).c_str());
	printf("    Native Minimum Luminance: %s\n",
	       ieee7542d(x[0x1c] | (x[0x1d] << 8)).c_str());
	printf("    Native Color Depth: ");
	if (!(x[0x1e] & 0x07))
		printf("Not defined\n");
	else if (bpc444[x[0x1e] & 0x07])
		printf("%s bpc\n", bpc444[x[0x1e] & 0x07]);
	else
		printf("Reserved\n");
	printf("    Display Device Technology: ");
	switch ((x[0x1e] >> 4) & 0x07) {
	case 0x00: printf("Not Specified\n"); break;
	case 0x01: printf("Active Matrix LCD\n"); break;
	case 0x02: printf("Organic LED\n"); break;
	default: printf("Reserved\n"); break;
	}
	if (block_rev)
		printf("    Display Device Theme Preference: %s\n",
		       (x[0x1e] & 0x80) ? "Dark Theme Preferred" : "No Preference");
	if (x[0x1f] != 0xff)
		printf("    Native Gamma EOTF: %.2f\n",
		       (100 + x[0x1f]) / 100.0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1d, %edx
xorl %ecx, %ecx
movl %edx, %esi
callq 0x21f90
testb $0x1, %al
jne 0x2650c
jmp 0x26ba8
movq -0xa0(%rbp), %rax
movq -0x10(%rbp), %rcx
movzbl 0x4(%rcx), %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rdx
movzbl 0x3(%rdx), %edx
addl %edx, %ecx
movl %ecx, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
shll $0x8, %ecx
movq -0x10(%rbp), %rdx
movzbl 0x5(%rdx), %edx
addl %edx, %ecx
movl %ecx, -0x1c(%rbp)
movb $0x1, 0x91f(%rax)
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x26572
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
leaq 0x194d0(%rip), %rdi     # 0x3fa39
movb $0x0, %al
callq 0x4050
jmp 0x265a8
movl -0x18(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd 0x175d6(%rip), %xmm1    # 0x3db58
divsd %xmm1, %xmm0
movl -0x1c(%rbp), %eax
cvtsi2sd %rax, %xmm1
movsd 0x175c2(%rip), %xmm2    # 0x3db58
divsd %xmm2, %xmm1
leaq 0x17d80(%rip), %rdi     # 0x3e321
movb $0x2, %al
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x26613
cmpl $0x0, -0x24(%rbp)
je 0x26613
movl -0x20(%rbp), %esi
movl -0x24(%rbp), %edx
leaq 0x19467(%rip), %rdi     # 0x3fa58
movb $0x0, %al
callq 0x4050
movq -0xa0(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %ecx, 0x940(%rax)
movl -0x24(%rbp), %ecx
movl %ecx, 0x944(%rax)
jmp 0x26637
cmpl $0x0, -0x20(%rbp)
jne 0x2661f
cmpl $0x0, -0x24(%rbp)
je 0x26635
movl -0x20(%rbp), %edx
movl -0x24(%rbp), %ecx
xorl %edi, %edi
leaq 0x19444(%rip), %rsi     # 0x3fa72
movb $0x0, %al
callq 0x47d0
jmp 0x26637
movq -0x10(%rbp), %rax
movb 0xb(%rax), %al
movb %al, -0x25(%rbp)
leaq 0x19448(%rip), %rdi     # 0x3fa90
xorl %eax, %eax
callq 0x4050
movzbl -0x25(%rbp), %eax
andl $0x7, %eax
movl %eax, %ecx
movq %rcx, -0xa8(%rbp)
subl $0x7, %eax
ja 0x266fd
movq -0xa8(%rbp), %rax
leaq 0x17746(%rip), %rcx     # 0x3ddbc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x19421(%rip), %rdi     # 0x3faa7
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x1942f(%rip), %rdi     # 0x3fac5
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x1943d(%rip), %rdi     # 0x3fae3
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x1944b(%rip), %rdi     # 0x3fb01
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x19459(%rip), %rdi     # 0x3fb1f
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x19467(%rip), %rdi     # 0x3fb3d
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x19475(%rip), %rdi     # 0x3fb5b
movb $0x0, %al
callq 0x4050
jmp 0x266fd
leaq 0x19483(%rip), %rdi     # 0x3fb79
movb $0x0, %al
callq 0x4050
leaq 0x19493(%rip), %rdi     # 0x3fb97
xorl %eax, %eax
callq 0x4050
movzbl -0x25(%rbp), %eax
shrl $0x3, %eax
andl $0x3, %eax
movl %eax, -0xac(%rbp)
je 0x2672c
jmp 0x2671f
movl -0xac(%rbp), %eax
subl $0x1, %eax
je 0x2673c
jmp 0x2674c
leaq 0x19480(%rip), %rdi     # 0x3fbb3
movb $0x0, %al
callq 0x4050
jmp 0x2675a
leaq 0x1948a(%rip), %rdi     # 0x3fbcd
movb $0x0, %al
callq 0x4050
jmp 0x2675a
leaq 0x18ed1(%rip), %rdi     # 0x3f624
movb $0x0, %al
callq 0x4050
movzbl -0x25(%rbp), %eax
testb $0x40, %al
movl $0x7b8, %eax            # imm = 0x7B8
movl $0x78b, %esi            # imm = 0x78B
cmovnel %eax, %esi
leaq 0x19479(%rip), %rdi     # 0x3fbed
xorl %eax, %eax
movb %al, -0xad(%rbp)
callq 0x4050
movb -0xad(%rbp), %al
movb -0x25(%rbp), %cl
testb %cl, %cl
leaq 0x1aeb1(%rip), %rcx     # 0x41644
leaq 0x971f(%rip), %rsi      # 0x2feb9
cmovsq %rcx, %rsi
leaq 0x19467(%rip), %rdi     # 0x3fc0c
callq 0x4050
movb -0xad(%rbp), %al
leaq 0x19482(%rip), %rdi     # 0x3fc39
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %edi
movzbl 0xd(%rax), %eax
andl $0xf, %eax
shll $0x8, %eax
orl %eax, %edi
callq 0x223f0
movsd %xmm0, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xd(%rax), %edi
shrl $0x4, %edi
movzbl 0xe(%rax), %eax
shll $0x4, %eax
orl %eax, %edi
callq 0x223f0
movaps %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
leaq 0x19451(%rip), %rdi     # 0x3fc59
movb $0x2, %al
movb %al, -0xc1(%rbp)
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0xf(%rax), %edi
movzbl 0x10(%rax), %eax
andl $0xf, %eax
shll $0x8, %eax
orl %eax, %edi
callq 0x223f0
movsd %xmm0, -0xd8(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %edi
shrl $0x4, %edi
movzbl 0x11(%rax), %eax
shll $0x4, %eax
orl %eax, %edi
callq 0x223f0
movb -0xc1(%rbp), %al
movaps %xmm0, %xmm1
movsd -0xd8(%rbp), %xmm0
leaq 0x19413(%rip), %rdi     # 0x3fc7a
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x12(%rax), %edi
movzbl 0x13(%rax), %eax
andl $0xf, %eax
shll $0x8, %eax
orl %eax, %edi
callq 0x223f0
movsd %xmm0, -0xd0(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %edi
shrl $0x4, %edi
movzbl 0x14(%rax), %eax
shll $0x4, %eax
orl %eax, %edi
callq 0x223f0
movb -0xc1(%rbp), %al
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
leaq 0x193dd(%rip), %rdi     # 0x3fc9b
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x15(%rax), %edi
movzbl 0x16(%rax), %eax
andl $0xf, %eax
shll $0x8, %eax
orl %eax, %edi
callq 0x223f0
movsd %xmm0, -0xc0(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x16(%rax), %edi
shrl $0x4, %edi
movzbl 0x17(%rax), %eax
shll $0x4, %eax
orl %eax, %edi
callq 0x223f0
movb -0xc1(%rbp), %al
movaps %xmm0, %xmm1
movsd -0xc0(%rbp), %xmm0
leaq 0x193a7(%rip), %rdi     # 0x3fcbc
callq 0x4050
movq -0x10(%rbp), %rax
movzwl 0x18(%rax), %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x26bc0
movq -0xb8(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
movb -0xad(%rbp), %al
leaq 0x1938f(%rip), %rdi     # 0x3fcdd
callq 0x4050
jmp 0x26955
leaq -0x48(%rbp), %rdi
callq 0x41f0
movq -0x10(%rbp), %rax
movzwl 0x1a(%rax), %esi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x26bc0
movq -0xe8(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x19383(%rip), %rdi     # 0x3fd0f
xorl %eax, %eax
callq 0x4050
jmp 0x26995
leaq -0x78(%rbp), %rdi
callq 0x41f0
movq -0x10(%rbp), %rax
movzwl 0x1c(%rax), %esi
leaq -0x98(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x26bc0
movq -0xf0(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x1937e(%rip), %rdi     # 0x3fd4d
xorl %eax, %eax
callq 0x4050
jmp 0x269d8
leaq -0x98(%rbp), %rdi
callq 0x41f0
leaq 0x19384(%rip), %rdi     # 0x3fd6f
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x1e(%rax), %eax
andl $0x7, %eax
cmpl $0x0, %eax
jne 0x26a66
leaq 0x153c3(%rip), %rdi     # 0x3bdcc
movb $0x0, %al
callq 0x4050
jmp 0x26abb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x41f0
jmp 0x26bb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x41f0
jmp 0x26bb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41f0
jmp 0x26bb1
movq -0x10(%rbp), %rax
movzbl 0x1e(%rax), %eax
andl $0x7, %eax
movslq %eax, %rcx
leaq 0x24f25(%rip), %rax     # 0x4b9a0
cmpq $0x0, (%rax,%rcx,8)
je 0x26aab
movq -0x10(%rbp), %rax
movzbl 0x1e(%rax), %eax
andl $0x7, %eax
movslq %eax, %rcx
leaq 0x24f09(%rip), %rax     # 0x4b9a0
movq (%rax,%rcx,8), %rsi
leaq 0x192e6(%rip), %rdi     # 0x3fd88
movb $0x0, %al
callq 0x4050
jmp 0x26ab9
leaq 0x18b72(%rip), %rdi     # 0x3f624
movb $0x0, %al
callq 0x4050
jmp 0x26abb
leaq 0x17c7e(%rip), %rdi     # 0x3e740
xorl %eax, %eax
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x1e(%rax), %eax
shrl $0x4, %eax
andl $0x7, %eax
movl %eax, -0xf4(%rbp)
je 0x26afb
jmp 0x26ae1
movl -0xf4(%rbp), %eax
subl $0x1, %eax
je 0x26b0b
jmp 0x26aee
movl -0xf4(%rbp), %eax
subl $0x2, %eax
je 0x26b1b
jmp 0x26b2b
leaq 0x1928e(%rip), %rdi     # 0x3fd90
movb $0x0, %al
callq 0x4050
jmp 0x26b39
leaq 0x1928d(%rip), %rdi     # 0x3fd9f
movb $0x0, %al
callq 0x4050
jmp 0x26b39
leaq 0x19290(%rip), %rdi     # 0x3fdb2
movb $0x0, %al
callq 0x4050
jmp 0x26b39
leaq 0x18af2(%rip), %rdi     # 0x3f624
movb $0x0, %al
callq 0x4050
cmpl $0x0, -0x14(%rbp)
je 0x26b70
movq -0x10(%rbp), %rax
movzbl 0x1e(%rax), %ecx
andl $0x80, %ecx
leaq 0x192a9(%rip), %rsi     # 0x3fdfd
leaq 0x1928d(%rip), %rax     # 0x3fde8
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x19256(%rip), %rdi     # 0x3fdbf
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x1f(%rax), %eax
cmpl $0xff, %eax
je 0x26ba8
movq -0x10(%rbp), %rax
movzbl 0x1f(%rax), %eax
addl $0x64, %eax
cvtsi2sd %eax, %xmm0
movsd 0x84a2(%rip), %xmm1     # 0x2f038
divsd %xmm1, %xmm0
leaq 0x1926a(%rip), %rdi     # 0x3fe0b
movb $0x1, %al
callq 0x4050
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x4550
nopw (%rax,%rax)