// File: rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_type_6_timing(unsigned char const*)
void edid_state::parse_displayid_type_6_timing(const unsigned char *x)
{
	struct timings t = {};
	std::string s("aspect ");

	t.pixclk_khz = 1 + (x[0] + (x[1] << 8) + ((x[2] & 0x3f) << 16));
	t.hact = 1 + (x[3] | ((x[4] & 0x3f) << 8));
	if ((x[4] >> 7) & 0x1)
		t.pos_pol_hsync = true;
	unsigned hbl = 1 + (x[7] | ((x[9] & 0xf) << 8));
	t.hfp = 1 + (x[8] | ((x[9] & 0xf0) << 4));
	t.hsync = 1 + x[10];
	t.hbp = hbl - t.hfp - t.hsync;
	t.vact = 1 + (x[5] | ((x[6] & 0x3f) << 8));
	if ((x[6] >> 7) & 0x1)
		t.pos_pol_vsync = true;
	unsigned vbl = 1 + x[11];
	t.vfp = 1 + x[12];
	t.vsync = 1 + (x[13] & 0x0f);
	t.vbp = vbl - t.vfp - t.vsync;

	if (x[13] & 0x80) {
		t.interlaced = true;
		t.vfp /= 2;
		t.vsync /= 2;
		t.vbp /= 2;
	}
	calc_ratio(&t);
	s += std::to_string(t.hratio) + ":" + std::to_string(t.vratio);
	if (x[2] & 0x40) {
		double aspect_mult = x[14] * 3.0 / 256.0;
		unsigned size_mult = 1 + (x[16] >> 4);

		t.vsize_mm = size_mult * (1 + (x[15] | ((x[16] & 0xf) << 8)));
		t.hsize_mm = t.vsize_mm * aspect_mult;
	}

	switch ((x[13] >> 5) & 0x3) {
	case 0:
		s += ", no 3D stereo";
		break;
	case 1:
		s += ", 3D stereo";
		break;
	case 2:
		s += ", 3D stereo depends on user action";
		break;
	case 3:
		s += ", reserved";
		fail("Reserved stereo 0x03.\n");
		break;
	}

	if (x[2] & 0x80) {
		s += ", preferred";
		dispid.preferred_timings.push_back(timings_ext(t, "DTD", s));
	}

	print_timings("    ", &t, "DTD", s.c_str(), true);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x210(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movl $0x0, -0x20(%rbp)
leaq -0x91(%rbp), %rdi
movq %rdi, -0x208(%rbp)
callq 0x4560
movq -0x208(%rbp), %rdx
leaq 0x185e8(%rip), %rsi     # 0x3e4f5
leaq -0x90(%rbp), %rdi
callq 0xb510
jmp 0x25f1b
leaq -0x91(%rbp), %rdi
callq 0x4370
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
andl $0x3f, %ecx
shll $0x10, %ecx
addl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x4(%rcx), %ecx
andl $0x3f, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x25fab
movb $0x1, -0x48(%rbp)
jmp 0x25fab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x91(%rbp), %rdi
callq 0x4370
jmp 0x264be
movq -0x10(%rbp), %rax
movzbl 0x7(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
andl $0xf, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0xa8(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
andl $0xf0, %ecx
shll $0x4, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0xa8(%rbp), %eax
subl -0x54(%rbp), %eax
subl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x6(%rcx), %ecx
andl $0x3f, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2603f
movb $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xb(%rax), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xd(%rax), %eax
andl $0xf, %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0xac(%rbp), %eax
subl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xd(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x260b2
movb $0x1, -0x58(%rbp)
movl -0x44(%rbp), %eax
shrl %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
shrl %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x3c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4c30
jmp 0x260bd
movl -0x68(%rbp), %esi
leaq -0x110(%rbp), %rdi
callq 0xb6d0
jmp 0x260ce
leaq 0xb285(%rip), %rdx      # 0x3135a
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xb4c0
jmp 0x260ea
movl -0x64(%rbp), %esi
leaq -0x130(%rbp), %rdi
callq 0xb6d0
jmp 0x260fb
leaq -0xd0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0xb7b0
jmp 0x26117
leaq -0x90(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x43f0
jmp 0x2612c
leaq -0xd0(%rbp), %rdi
callq 0x41f0
leaq -0x130(%rbp), %rdi
callq 0x41f0
leaq -0xf0(%rbp), %rdi
callq 0x41f0
leaq -0x110(%rbp), %rdi
callq 0x41f0
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x26290
movq -0x10(%rbp), %rax
movzbl 0xe(%rax), %eax
cvtsi2sd %eax, %xmm0
movsd 0x179e4(%rip), %xmm1    # 0x3db68
mulsd %xmm1, %xmm0
movsd 0x131e0(%rip), %xmm1    # 0x39370
mulsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %eax
shrl $0x4, %eax
incl %eax
movl %eax, -0x13c(%rbp)
movl -0x13c(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl 0xf(%rcx), %edx
movzbl 0x10(%rcx), %esi
andl $0xf, %esi
shll $0x8, %esi
movl %edx, %ecx
movl %esi, %edx
leal 0x1(%rcx,%rdx), %ecx
imull %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cvtsi2sd %rax, %xmm0
movsd -0x138(%rbp), %xmm1
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x28(%rbp)
jmp 0x26290
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x264b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x2627f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x26273
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x26267
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x41f0
leaq -0x130(%rbp), %rdi
callq 0x41f0
leaq -0xf0(%rbp), %rdi
callq 0x41f0
leaq -0x110(%rbp), %rdi
callq 0x41f0
jmp 0x264b2
movq -0x10(%rbp), %rax
movzbl 0xd(%rax), %eax
shrl $0x5, %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, -0x218(%rbp)
subl $0x3, %eax
ja 0x26336
movq -0x218(%rbp), %rax
leaq 0x17aee(%rip), %rcx     # 0x3ddac
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x18263(%rip), %rsi     # 0x3e531
leaq -0x90(%rbp), %rdi
callq 0x4300
jmp 0x262dc
jmp 0x26336
leaq 0x1825b(%rip), %rsi     # 0x3e540
leaq -0x90(%rbp), %rdi
callq 0x4300
jmp 0x262f3
jmp 0x26336
leaq 0x18250(%rip), %rsi     # 0x3e54c
leaq -0x90(%rbp), %rdi
callq 0x4300
jmp 0x2630a
jmp 0x26336
leaq 0x13a68(%rip), %rsi     # 0x39d7b
leaq -0x90(%rbp), %rdi
callq 0x4300
jmp 0x26321
leaq 0x18247(%rip), %rsi     # 0x3e56f
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x26334
jmp 0x26336
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x2645f
leaq 0x18241(%rip), %rsi     # 0x3e594
leaq -0x90(%rbp), %rdi
callq 0x4300
jmp 0x26361
movq -0x210(%rbp), %rax
addq $0x928, %rax            # imm = 0x928
movq %rax, -0x228(%rbp)
leaq -0x1f9(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x4560
movq -0x220(%rbp), %rdx
leaq 0x9059(%rip), %rsi      # 0x2f3ef
leaq -0x1f8(%rbp), %rdi
callq 0xb510
jmp 0x263a4
leaq -0x1d8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x1f8(%rbp), %rdx
leaq -0x90(%rbp), %rcx
callq 0x148f0
jmp 0x263c4
movq -0x228(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
callq 0x1ff90
jmp 0x263d9
leaq -0x1d8(%rbp), %rdi
callq 0xc3d0
leaq -0x1f8(%rbp), %rdi
callq 0x41f0
leaq -0x1f9(%rbp), %rdi
callq 0x4370
jmp 0x2645f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x26451
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x26445
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xc3d0
leaq -0x1f8(%rbp), %rdi
callq 0x41f0
leaq -0x1f9(%rbp), %rdi
callq 0x4370
jmp 0x264b2
leaq -0x90(%rbp), %rdi
callq 0x4150
movq -0x210(%rbp), %rdi
movq %rax, %r8
movq %rsp, %rax
movl $0x1, (%rax)
leaq 0xe35a(%rip), %rsi      # 0x347df
leaq 0x8f63(%rip), %rcx      # 0x2f3ef
leaq -0x70(%rbp), %rdx
movl $0x1, %r9d
callq 0x50c0
jmp 0x2649d
leaq -0x90(%rbp), %rdi
callq 0x41f0
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x90(%rbp), %rdi
callq 0x41f0
movq -0xa0(%rbp), %rdi
callq 0x4550
nopw (%rax,%rax)