// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x1d
popq %rdx
movq %rsi, %rdi
movl %edx, %esi
xorl %ecx, %ecx
callq 0x126fe
testb %al, %al
je 0x153fe
movzwl 0x3(%rbx), %esi
movzwl 0x5(%rbx), %edx
movb $0x1, 0x91f(%r14)
cmpb $0x0, 0x1(%rbx)
js 0x1508b
cvtsi2sd %esi, %xmm0
movsd 0x135c1(%rip), %xmm2    # 0x28630
divsd %xmm2, %xmm0
cvtsi2sd %edx, %xmm1
divsd %xmm2, %xmm1
leaq 0x13bf3(%rip), %rdi     # 0x28c75
movb $0x2, %al
callq 0x3030
jmp 0x15099
leaq 0x14933(%rip), %rdi     # 0x299c5
xorl %eax, %eax
callq 0x3030
movzwl 0x7(%rbx), %r12d
movzwl 0x9(%rbx), %r15d
testl %r12d, %r12d
je 0x150d1
testl %r15d, %r15d
je 0x150d1
leaq 0x14930(%rip), %rdi     # 0x299e4
movl %r12d, %esi
movl %r15d, %edx
xorl %eax, %eax
callq 0x3030
movl %r12d, 0x940(%r14)
movl %r15d, 0x944(%r14)
jmp 0x150ef
movl %r12d, %eax
orl %r15d, %eax
je 0x150ef
leaq 0x1491e(%rip), %rsi     # 0x299fe
xorl %edi, %edi
movl %r12d, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x362c
movzbl 0xb(%rbx), %r15d
leaq 0x14921(%rip), %rdi     # 0x29a1c
xorl %eax, %eax
callq 0x3030
movl %r15d, %eax
andl $0x7, %eax
leaq 0x13a55(%rip), %rcx     # 0x28b64
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
callq 0x33b0
leaq 0x14911(%rip), %rdi     # 0x29a33
xorl %eax, %eax
callq 0x3030
movl %r15d, %eax
shrl $0x3, %eax
andl $0x3, %eax
cmpl $0x1, %eax
leaq 0x166ac(%rip), %rcx     # 0x2b7e8
leaq 0x1647d(%rip), %r14     # 0x2b5c0
cmovneq %r14, %rcx
testl %eax, %eax
leaq 0x166b7(%rip), %rdi     # 0x2b807
cmovneq %rcx, %rdi
callq 0x33b0
testb $0x40, %r15b
movl $0x78b, %eax            # imm = 0x78B
movl $0x7b8, %esi            # imm = 0x7B8
cmovel %eax, %esi
leaq 0x148de(%rip), %rdi     # 0x29a4f
xorl %eax, %eax
callq 0x3030
testb %r15b, %r15b
leaq 0x5b07(%rip), %rax      # 0x1ac89
leaq 0x16c0b(%rip), %rsi     # 0x2bd94
cmovnsq %rax, %rsi
leaq 0x148da(%rip), %rdi     # 0x29a6e
xorl %eax, %eax
callq 0x3030
leaq 0x1667e(%rip), %rdi     # 0x2b820
callq 0x33b0
movzbl 0xc(%rbx), %eax
movzbl 0xd(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
cvtsi2sd %edx, %xmm0
movsd 0xedc3(%rip), %xmm2     # 0x23f88
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl 0xe(%rbx), %eax
shll $0x4, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x148b7(%rip), %rdi     # 0x29a9b
movb $0x2, %al
callq 0x3030
movzbl 0xf(%rbx), %eax
movzbl 0x10(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
cvtsi2sd %edx, %xmm0
movsd 0xed7f(%rip), %xmm2     # 0x23f88
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl 0x11(%rbx), %eax
shll $0x4, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x14894(%rip), %rdi     # 0x29abc
movb $0x2, %al
callq 0x3030
movzbl 0x12(%rbx), %eax
movzbl 0x13(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
cvtsi2sd %edx, %xmm0
movsd 0xed3b(%rip), %xmm2     # 0x23f88
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl 0x14(%rbx), %eax
shll $0x4, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x14871(%rip), %rdi     # 0x29add
movb $0x2, %al
callq 0x3030
movzbl 0x15(%rbx), %eax
movzbl 0x16(%rbx), %ecx
movl %ecx, %edx
andl $0xf, %edx
shll $0x8, %edx
orl %eax, %edx
cvtsi2sd %edx, %xmm0
movsd 0xecf7(%rip), %xmm2     # 0x23f88
mulsd %xmm2, %xmm0
shrl $0x4, %ecx
movzbl 0x17(%rbx), %eax
shll $0x4, %eax
orl %ecx, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
leaq 0x1484e(%rip), %rdi     # 0x29afe
movb $0x2, %al
callq 0x3030
movzwl 0x18(%rbx), %esi
movq %rsp, %r15
movq %r15, %rdi
callq 0x1540b
movq (%r15), %rsi
leaq 0x1484f(%rip), %rdi     # 0x29b1f
xorl %eax, %eax
callq 0x3030
movq %r15, %rdi
callq 0x3130
movzwl 0x1a(%rbx), %esi
movq %rsp, %r15
movq %r15, %rdi
callq 0x1540b
movq (%r15), %rsi
leaq 0x14859(%rip), %rdi     # 0x29b51
xorl %eax, %eax
callq 0x3030
movq %r15, %rdi
callq 0x3130
movzwl 0x1c(%rbx), %esi
movq %rsp, %r15
movq %r15, %rdi
callq 0x1540b
movq (%r15), %rsi
leaq 0x1486f(%rip), %rdi     # 0x29b8f
xorl %eax, %eax
callq 0x3030
movq %r15, %rdi
callq 0x3130
leaq 0x1487b(%rip), %rdi     # 0x29bb1
xorl %eax, %eax
callq 0x3030
movzbl 0x1e(%rbx), %eax
andq $0x7, %rax
je 0x15367
leaq 0x1f2a2(%rip), %rcx     # 0x345f0
movq (%rcx,%rax,8), %rsi
testq %rsi, %rsi
je 0x15370
leaq 0x1486c(%rip), %rdi     # 0x29bca
xorl %eax, %eax
callq 0x3030
jmp 0x1537c
leaq 0x12a2f(%rip), %rdi     # 0x27d9d
jmp 0x15377
leaq 0x16249(%rip), %rdi     # 0x2b5c0
callq 0x33b0
leaq 0x13c92(%rip), %rdi     # 0x29015
xorl %eax, %eax
callq 0x3030
movzbl 0x1e(%rbx), %eax
shrl $0x4, %eax
andl $0x7, %eax
cmpb $0x2, %al
ja 0x153a6
leaq 0x137e5(%rip), %rcx     # 0x28b84
movslq (%rcx,%rax,4), %r14
addq %rcx, %r14
movq %r14, %rdi
callq 0x33b0
testl %ebp, %ebp
je 0x153d6
cmpb $0x0, 0x1e(%rbx)
leaq 0x14853(%rip), %rax     # 0x29c10
leaq 0x14837(%rip), %rsi     # 0x29bfb
cmovnsq %rax, %rsi
leaq 0x14803(%rip), %rdi     # 0x29bd2
xorl %eax, %eax
callq 0x3030
movzbl 0x1f(%rbx), %eax
cmpl $0xff, %eax
je 0x153fe
addl $0x64, %eax
cvtsi2sd %eax, %xmm0
divsd 0x4c30(%rip), %xmm0     # 0x1a020
leaq 0x14827(%rip), %rdi     # 0x29c1e
movb $0x1, %al
callq 0x3030
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq