// File: rpavlik[P]edid-decode/parse-displayid-block.cpp
// Function: edid_state::parse_displayid_type_1_7_timing(unsigned char const*, bool, unsigned int, bool)
void edid_state::parse_displayid_type_1_7_timing(const unsigned char *x,
						 bool type7, unsigned block_rev, bool is_cta)
{
	struct timings t = {};
	unsigned hbl, vbl;
	std::string s("aspect ");

	dispid.has_type_1_7 = true;
	t.pixclk_khz = (type7 ? 1 : 10) * (1 + (x[0] + (x[1] << 8) + (x[2] << 16)));
	switch (x[3] & 0xf) {
	case 0:
		s += "1:1";
		t.hratio = t.vratio = 1;
		break;
	case 1:
		s += "5:4";
		t.hratio = 5;
		t.vratio = 4;
		break;
	case 2:
		s += "4:3";
		t.hratio = 4;
		t.vratio = 3;
		break;
	case 3:
		s += "15:9";
		t.hratio = 15;
		t.vratio = 9;
		break;
	case 4:
		s += "16:9";
		t.hratio = 16;
		t.vratio = 9;
		break;
	case 5:
		s += "16:10";
		t.hratio = 16;
		t.vratio = 10;
		break;
	case 6:
		s += "64:27";
		t.hratio = 64;
		t.vratio = 27;
		break;
	case 7:
		s += "256:135";
		t.hratio = 256;
		t.vratio = 135;
		break;
	default:
		s += "undefined";
		if ((x[3] & 0xf) > (dispid.version <= 0x12 ? 7 : 8))
			fail("Unknown aspect 0x%02x.\n", x[3] & 0xf);
		break;
	}
	switch ((x[3] >> 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 (block_rev >= 2 && (x[3] & 0x80))
		s += ", YCbCr 4:2:0";

	t.hact = 1 + (x[4] | (x[5] << 8));
	hbl = 1 + (x[6] | (x[7] << 8));
	t.hfp = 1 + (x[8] | ((x[9] & 0x7f) << 8));
	t.hsync = 1 + (x[10] | (x[11] << 8));
	t.hbp = hbl - t.hfp - t.hsync;
	if ((x[9] >> 7) & 0x1)
		t.pos_pol_hsync = true;
	t.vact = 1 + (x[12] | (x[13] << 8));
	vbl = 1 + (x[14] | (x[15] << 8));
	t.vfp = 1 + (x[16] | ((x[17] & 0x7f) << 8));
	t.vsync = 1 + (x[18] | (x[19] << 8));
	t.vbp = vbl - t.vfp - t.vsync;
	if ((x[17] >> 7) & 0x1)
		t.pos_pol_vsync = true;

	if (x[3] & 0x10) {
		t.interlaced = true;
		t.vfp /= 2;
		t.vsync /= 2;
		t.vbp /= 2;
	}
	if (block_rev < 2 && (x[3] & 0x80)) {
		s += ", preferred";
		dispid.preferred_timings.push_back(timings_ext(t, "DTD", s));
	}

	print_timings("    ", &t, "DTD", s.c_str(), true);
	if (is_cta) {
		timings_ext te(t, "DTD", s);
		cta.vec_vtdbs.push_back(te);

		// Only use a T7VTDB if is cannot be expressed by a
		// DTD or a T10VTDB.
		if (t.hact <= 4095 && t.vact <= 4095 &&
		    t.pixclk_khz <= 655360 && !(x[3] & 0xe0)) {
			fail("This T7VTDB can be represented as an 18-byte DTD.\n");
			return;
		}
		unsigned htot = t.hact + t.hfp + t.hsync + t.hbp;
		unsigned vtot = t.vact + t.vfp + t.vsync + t.vbp;
		unsigned refresh = (t.pixclk_khz * 1000ULL) / (htot * vtot);

		for (unsigned rb = RB_NONE; rb <= RB_CVT_V3; rb++) {
			timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, rb);
			if (match_timings(t, cvt_t)) {
				fail("This T7VTDB can be represented as a T10VTDB.\n");
				return;
			}
		}
		timings cvt_t = calc_cvt_mode(t.hact, t.vact, refresh, RB_CVT_V3,
					      false, false, true);
		if (match_timings(t, cvt_t))
			fail("This T7VTDB can be represented as a T10VTDB.\n");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x340, %rsp            # imm = 0x340
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %dl
movb %dl, -0x11(%rbp)
movl %ecx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2f8(%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 -0x99(%rbp), %rdi
movq %rdi, -0x2f0(%rbp)
callq 0x4560
movq -0x2f0(%rbp), %rdx
leaq 0x1c067(%rip), %rsi     # 0x3e4f5
leaq -0x98(%rbp), %rdi
callq 0xb510
jmp 0x2249c
leaq -0x99(%rbp), %rdi
callq 0x4370
movq -0x2f8(%rbp), %rax
movb $0x1, 0x920(%rax)
movb -0x11(%rbp), %al
notb %al
movzbl %al, %ecx
andl $0x1, %ecx
movl %ecx, %eax
leal 0x1(%rax,%rax,8), %eax
movq -0x10(%rbp), %rcx
movzwl (%rcx), %edx
movzbl 0x2(%rcx), %esi
shll $0x10, %esi
movl %edx, %ecx
movl %esi, %edx
leal 0x1(%rcx,%rdx), %ecx
imull %ecx, %eax
movl %eax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0xf, %eax
movl %eax, %ecx
movq %rcx, -0x300(%rbp)
subl $0x7, %eax
ja 0x2268e
movq -0x300(%rbp), %rax
leaq 0x1b67a(%rip), %rcx     # 0x3db88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x99(%rbp), %rdi
callq 0x4370
jmp 0x22db3
leaq 0x1bfbc(%rip), %rsi     # 0x3e4fd
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2254f
movl $0x1, -0x64(%rbp)
movl $0x1, -0x68(%rbp)
jmp 0x226f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x22da7
leaq 0x11929(%rip), %rsi     # 0x33ea9
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2258e
movl $0x5, -0x68(%rbp)
movl $0x4, -0x64(%rbp)
jmp 0x226f2
leaq 0x118ef(%rip), %rsi     # 0x33e97
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x225b6
movl $0x4, -0x68(%rbp)
movl $0x3, -0x64(%rbp)
jmp 0x226f2
leaq 0x118de(%rip), %rsi     # 0x33eae
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x225de
movl $0xf, -0x68(%rbp)
movl $0x9, -0x64(%rbp)
jmp 0x226f2
leaq 0x118a4(%rip), %rsi     # 0x33e9c
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x22606
movl $0x10, -0x68(%rbp)
movl $0x9, -0x64(%rbp)
jmp 0x226f2
leaq 0x11882(%rip), %rsi     # 0x33ea2
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2262e
movl $0x10, -0x68(%rbp)
movl $0xa, -0x64(%rbp)
jmp 0x226f2
leaq 0x1beb9(%rip), %rsi     # 0x3e501
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x22656
movl $0x40, -0x68(%rbp)
movl $0x1b, -0x64(%rbp)
jmp 0x226f2
leaq 0x1be97(%rip), %rsi     # 0x3e507
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2267e
movl $0x100, -0x68(%rbp)     # imm = 0x100
movl $0x87, -0x64(%rbp)
jmp 0x226f2
leaq 0x1be7a(%rip), %rsi     # 0x3e50f
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x226a3
movq -0x2f8(%rbp), %rcx
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0xf, %eax
movzbl 0x910(%rcx), %esi
movl $0x8, %ecx
movl $0x7, %edx
cmpl $0x12, %esi
cmovlel %edx, %ecx
cmpl %ecx, %eax
jle 0x226f0
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %edx
andl $0xf, %edx
leaq 0x1be37(%rip), %rsi     # 0x3e519
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x226ee
jmp 0x226f0
jmp 0x226f2
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
shrl $0x5, %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, -0x308(%rbp)
subl $0x3, %eax
ja 0x22798
movq -0x308(%rbp), %rax
leaq 0x1b488(%rip), %rcx     # 0x3dba8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1be01(%rip), %rsi     # 0x3e531
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2273e
jmp 0x22798
leaq 0x1bdf9(%rip), %rsi     # 0x3e540
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x22755
jmp 0x22798
leaq 0x1bdee(%rip), %rsi     # 0x3e54c
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x2276c
jmp 0x22798
leaq 0x17606(%rip), %rsi     # 0x39d7b
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x22783
leaq 0x1bde5(%rip), %rsi     # 0x3e56f
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x22796
jmp 0x22798
cmpl $0x2, -0x18(%rbp)
jb 0x227c7
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x227c7
leaq 0x1bdcf(%rip), %rsi     # 0x3e586
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x227c5
jmp 0x227c7
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x5(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x7(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x9(%rcx), %ecx
andl $0x7f, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x74(%rbp), %eax
subl -0x54(%rbp), %eax
subl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x22859
movb $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xd(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0xe(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xf(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x11(%rcx), %ecx
andl $0x7f, %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x12(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x13(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x78(%rbp), %eax
subl -0x44(%rbp), %eax
subl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x11(%rax), %eax
sarl $0x7, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x228eb
movb $0x1, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x2291d
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)
cmpl $0x2, -0x18(%rbp)
jae 0x22a53
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x22a53
leaq 0x1bc50(%rip), %rsi     # 0x3e594
leaq -0x98(%rbp), %rdi
callq 0x4300
jmp 0x22952
movq -0x2f8(%rbp), %rax
addq $0x928, %rax            # imm = 0x928
movq %rax, -0x318(%rbp)
leaq -0x169(%rbp), %rdi
movq %rdi, -0x310(%rbp)
callq 0x4560
movq -0x310(%rbp), %rdx
leaq 0xca68(%rip), %rsi      # 0x2f3ef
leaq -0x168(%rbp), %rdi
callq 0xb510
jmp 0x22995
leaq -0x148(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x168(%rbp), %rdx
leaq -0x98(%rbp), %rcx
callq 0x148f0
jmp 0x229b5
movq -0x318(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x1ff90
jmp 0x229ca
leaq -0x148(%rbp), %rdi
callq 0xc3d0
leaq -0x168(%rbp), %rdi
callq 0x41f0
leaq -0x169(%rbp), %rdi
callq 0x4370
jmp 0x22a53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x22a42
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x22a36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x148(%rbp), %rdi
callq 0xc3d0
leaq -0x168(%rbp), %rdi
callq 0x41f0
leaq -0x169(%rbp), %rdi
callq 0x4370
jmp 0x22da7
leaq -0x98(%rbp), %rdi
callq 0x4150
movq -0x2f8(%rbp), %rdi
movq %rax, %r8
movq %rsp, %rax
movl $0x1, (%rax)
leaq 0x11d66(%rip), %rsi     # 0x347df
leaq 0xc96f(%rip), %rcx      # 0x2f3ef
leaq -0x70(%rbp), %rdx
movl $0x1, %r9d
callq 0x50c0
jmp 0x22a91
testb $0x1, -0x19(%rbp)
je 0x22d88
leaq -0x229(%rbp), %rdi
movq %rdi, -0x320(%rbp)
callq 0x4560
movq -0x320(%rbp), %rdx
leaq 0xc933(%rip), %rsi      # 0x2f3ef
leaq -0x228(%rbp), %rdi
callq 0xb510
jmp 0x22aca
leaq -0x208(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x228(%rbp), %rdx
leaq -0x98(%rbp), %rcx
callq 0x148f0
jmp 0x22aea
leaq -0x228(%rbp), %rdi
callq 0x41f0
leaq -0x229(%rbp), %rdi
callq 0x4370
movq -0x2f8(%rbp), %rdi
addq $0x1a8, %rdi            # imm = 0x1A8
leaq -0x208(%rbp), %rsi
callq 0x14a20
jmp 0x22b1e
cmpl $0xfff, -0x70(%rbp)     # imm = 0xFFF
ja 0x22be3
cmpl $0xfff, -0x6c(%rbp)     # imm = 0xFFF
ja 0x22be3
cmpl $0xa0000, -0x60(%rbp)   # imm = 0xA0000
ja 0x22be3
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0xe0, %eax
cmpl $0x0, %eax
jne 0x22be3
leaq 0x1ba3e(%rip), %rsi     # 0x3e5a0
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x22b6e
movl $0x1, -0x230(%rbp)
jmp 0x22d6e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x22baf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x41f0
leaq -0x229(%rbp), %rdi
callq 0x4370
jmp 0x22da7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x208(%rbp), %rdi
callq 0xc3d0
jmp 0x22da7
movl -0x70(%rbp), %eax
addl -0x54(%rbp), %eax
addl -0x50(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x234(%rbp)
movl -0x6c(%rbp), %eax
addl -0x44(%rbp), %eax
addl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x238(%rbp)
movl -0x60(%rbp), %eax
imulq $0x3e8, %rax, %rax      # imm = 0x3E8
movl -0x234(%rbp), %ecx
imull -0x238(%rbp), %ecx
movl %ecx, %ecx
xorl %edx, %edx
divq %rcx
movl %eax, -0x23c(%rbp)
movl $0x0, -0x240(%rbp)
cmpl $0x3, -0x240(%rbp)
ja 0x22ce5
movq -0x2f8(%rbp), %rsi
movl -0x70(%rbp), %edx
movl -0x6c(%rbp), %ecx
movl -0x23c(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x240(%rbp), %r8d
movq %rsp, %rax
movl $0x0, 0x8(%rax)
movl $0x0, (%rax)
leaq -0x294(%rbp), %rdi
xorl %r9d, %r9d
callq 0x2d890
jmp 0x22c82
movq -0x2f8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x294(%rbp), %rdx
callq 0x4db0
movb %al, -0x321(%rbp)
jmp 0x22ca1
movb -0x321(%rbp), %al
testb $0x1, %al
jne 0x22cad
jmp 0x22ccf
leaq 0x1b91f(%rip), %rsi     # 0x3e5d3
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x22cc0
movl $0x1, -0x230(%rbp)
jmp 0x22d6e
jmp 0x22cd1
movl -0x240(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x240(%rbp)
jmp 0x22c35
movq -0x2f8(%rbp), %rsi
movl -0x70(%rbp), %edx
movl -0x6c(%rbp), %ecx
movl -0x23c(%rbp), %eax
cvtsi2sd %rax, %xmm0
movq %rsp, %rax
movl $0x1, 0x8(%rax)
movl $0x0, (%rax)
leaq -0x2e8(%rbp), %rdi
movl $0x3, %r8d
xorl %r9d, %r9d
callq 0x2d890
jmp 0x22d24
movq -0x2f8(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x2e8(%rbp), %rdx
callq 0x4db0
movb %al, -0x322(%rbp)
jmp 0x22d43
movb -0x322(%rbp), %al
testb $0x1, %al
jne 0x22d4f
jmp 0x22d64
leaq 0x1b87d(%rip), %rsi     # 0x3e5d3
xorl %edi, %edi
movb %dil, %al
callq 0x47d0
jmp 0x22d62
jmp 0x22d64
movl $0x0, -0x230(%rbp)
leaq -0x208(%rbp), %rdi
callq 0xc3d0
movl -0x230(%rbp), %eax
testl %eax, %eax
jne 0x22d92
jmp 0x22d86
jmp 0x22d88
movl $0x0, -0x230(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x41f0
addq $0x340, %rsp            # imm = 0x340
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x41f0
movq -0xa8(%rbp), %rdi
callq 0x4550
nop