// File: rpavlik[P]edid-decode/parse-di-ext-block.cpp
// Function: edid_state::parse_digital_interface(unsigned char const*)
void edid_state::parse_digital_interface(const unsigned char *x)
{
	data_block = "Digital Interface";
	printf("  %s:\n", data_block.c_str());

	printf("    Supported Digital Interface: ");
	unsigned short v = x[2];
	switch (v) {
	case 0x00:
		printf("Analog Video Input\n");
		if (!memchk(x + 2, 12))
			fail("Bytes 0x02-0x0d should be 0.\n");
		return;
	case 0x01: printf("DVI\n"); break;
	case 0x02: printf("DVI Single Link\n"); break;
	case 0x03: printf("DVI Dual Link - High Resolution\n"); break;
	case 0x04: printf("DVI Dual Link - High Color\n"); break;
	case 0x05: printf("DVI - Consumer Electronics\n"); break;
	case 0x06: printf("Plug & Display\n"); break;
	case 0x07: printf("DFP\n"); break;
	case 0x08: printf("Open LDI - Single Link\n"); break;
	case 0x09: printf("Open LDI - Dual Link\n"); break;
	case 0x0a: printf("Open LDI - Consumer Electronics\n"); break;
	default:
		   printf("Unknown (0x%02x)\n", v);
		   fail("Unknown Digital Interface 0x%02x.\n", v);
		   break;
	}

	switch ((x[3]) >> 6) {
	case 0x00:
		if (!memchk(x + 3, 4))
			fail("Bytes 0x03-0x06 should be 0.\n");
		break;
	case 0x01:
		printf("    Version: %u.%u\n    Release: %u.%u\n", x[3] & 0x3f, x[4], x[5], x[6]);
		if (x[4] > 99)
			fail("Version number > 99.\n");
		if (x[6] > 99)
			fail("Release number > 99.\n");
		break;
	case 0x02:
		if (x[3] & 0x3f)
			fail("Bits 5-0 of byte 0x03 should be 0.\n");
		if (x[5] || x[6])
			fail("Bytes 0x05-0x06 should be 0.\n");
		printf("    Letter Designation: %c\n", x[4]);
		break;
	case 0x03:
		if (x[3] & 0x3f)
			fail("Bits 5-0 of byte 0x03 should be 0.\n");
		printf("    Date Code: Year %u Week %u Day %u\n", 1990 + x[4], x[5], x[6]);
		if (!x[5] || x[5] > 12)
			fail("Bad month number.\n");
		if (!x[6] || x[6] > 31)
			fail("Bad day number.\n");
		break;
	}

	v = x[7];
	printf("    Data Enable Signal Usage %sAvailable\n",
	       (v & 0x80) ? "" : "Not ");
	if (v & 0x80)
		printf("    Data Enable Signal %s\n",
		       (v & 0x40) ? "High" : "Low");
	else if (v & 0x40)
		fail("Bit 6 of byte 0x07 should be 0.\n");
	printf("    Edge of Shift Clock: ");
	switch ((v >> 4) & 0x03) {
	case 0: printf("Not specified\n"); break;
	case 1: printf("Use rising edge of shift clock\n"); break;
	case 2: printf("Use falling edge of shift clock\n"); break;
	case 3: printf("Use both edges of shift clock\n"); break;
	}
	printf("    HDCP is %ssupported\n", (v & 0x08) ? "" : "not ");
	printf("    Digital Receivers %ssupport Double Clocking of Input Data\n",
	       (v & 0x04) ? "" : "do not ");
	printf("    Packetized Digital Video is %ssupported\n", (v & 0x02) ? "" : "not ");
	if (v & 0x01)
		fail("Bit 0 of byte 0x07 should be 0.\n");

	v = x[8];
	printf("    Data Formats: ");
	switch (v) {
	case 0x15: printf("8-Bit Over 8-Bit RGB\n"); break;
	case 0x19: printf("12-Bit Over 12-Bit RGB\n"); break;
	case 0x24: printf("24-Bit MSB-Aligned RGB (Single Link)\n"); break;
	case 0x48: printf("48-Bit MSB-Aligned RGB (Dual Link - High Resolution)\n"); break;
	case 0x49: printf("48-Bit MSB-Aligned RGB (Dual Link - High Color)\n"); break;
	default:
		   printf("Unknown (0x%02x)\n", v);
		   fail("Unknown Data Format 0x%02x.\n", v);
		   break;
	}
	if (x[2] == 0x03 && v != 0x48)
		fail("Data Format should be 0x48, not 0x%02x.\n", v);
	if (x[2] == 0x04 && v != 0x49)
		fail("Data Format should be 0x49, not 0x%02x.\n", v);

	v = x[9];
	if (v) {
		printf("    Minimum Pixel Clock Frequency Per Link: %u MHz\n", v);
		if (v == 0xff)
			fail("Invalid Min-PCF 0x%02x.\n", v);
	}

	v = x[10] | (x[11] << 8);
	if (v) {
		printf("    Maximum Pixel Clock Frequency Per Link: %u MHz\n", v);
		if (v == 0xffff)
			fail("Invalid Max-PCF 0x%04x.\n", v);
	}

	v = x[12] | (x[13] << 8);
	if (v == 0xffff)
		printf("    Crossover Frequency: None - Single Link\n");
	else if (v)
		printf("    Crossover Frequency: %u MHz\n", v);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x30(%rbp)
leaq 0x161e1(%rip), %rsi     # 0x41284
callq 0x4420
movq -0x30(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x9036(%rip), %rdi      # 0x340f1
xorl %eax, %eax
movb %al, -0x21(%rbp)
callq 0x4050
movb -0x21(%rbp), %al
leaq 0x161c7(%rip), %rdi     # 0x41296
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
movw %ax, -0x12(%rbp)
movzwl -0x12(%rbp), %eax
movq %rax, -0x20(%rbp)
subq $0xa, %rax
ja 0x2b1ed
movq -0x20(%rbp), %rax
leaq 0x1603b(%rip), %rcx     # 0x41138
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x161ab(%rip), %rdi     # 0x412b8
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rdi
addq $0x2, %rdi
movl $0xc, %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2b13c
xorl %edi, %edi
leaq 0x16197(%rip), %rsi     # 0x412cc
movb $0x0, %al
callq 0x47d0
jmp 0x2b77c
leaq 0x161a2(%rip), %rdi     # 0x412ea
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x16194(%rip), %rdi     # 0x412ef
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x16192(%rip), %rdi     # 0x41300
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161a0(%rip), %rdi     # 0x41321
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161a9(%rip), %rdi     # 0x4133d
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161b5(%rip), %rdi     # 0x41359
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161b5(%rip), %rdi     # 0x41369
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161aa(%rip), %rdi     # 0x4136e
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161b2(%rip), %rdi     # 0x41386
movb $0x0, %al
callq 0x4050
jmp 0x2b213
leaq 0x161b8(%rip), %rdi     # 0x4139c
movb $0x0, %al
callq 0x4050
jmp 0x2b213
movzwl -0x12(%rbp), %esi
leaq 0x9040(%rip), %rdi      # 0x34238
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x161b1(%rip), %rsi     # 0x413bd
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
shrl $0x6, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x3, %eax
ja 0x2b3da
movq -0x38(%rbp), %rax
leaq 0x15f2c(%rip), %rcx     # 0x41164
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rdi
addq $0x3, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2b269
xorl %edi, %edi
leaq 0x1617e(%rip), %rsi     # 0x413e0
movb $0x0, %al
callq 0x47d0
jmp 0x2b3da
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %esi
andl $0x3f, %esi
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %edx
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %ecx
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %r8d
leaq 0x16165(%rip), %rdi     # 0x413fe
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x63, %eax
jle 0x2b2bd
xorl %edi, %edi
leaq 0x1616f(%rip), %rsi     # 0x41425
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x63, %eax
jle 0x2b2da
xorl %edi, %edi
leaq 0x16168(%rip), %rsi     # 0x4143b
movb $0x0, %al
callq 0x47d0
jmp 0x2b3da
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x3f, %eax
cmpl $0x0, %eax
je 0x2b2ff
xorl %edi, %edi
leaq 0x16159(%rip), %rsi     # 0x41451
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x5(%rax)
jne 0x2b313
movq -0x10(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0x2b323
xorl %edi, %edi
leaq 0x16159(%rip), %rsi     # 0x41475
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %esi
leaq 0x16161(%rip), %rdi     # 0x41493
movb $0x0, %al
callq 0x4050
jmp 0x2b3da
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
andl $0x3f, %eax
cmpl $0x0, %eax
je 0x2b35e
xorl %edi, %edi
leaq 0x160fa(%rip), %rsi     # 0x41451
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %esi
addl $0x7c6, %esi            # imm = 0x7C6
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %edx
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %ecx
leaq 0x1612c(%rip), %rdi     # 0x414af
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rax
cmpb $0x0, 0x5(%rax)
je 0x2b3a1
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
cmpl $0xc, %eax
jle 0x2b3b1
xorl %edi, %edi
leaq 0x1612c(%rip), %rsi     # 0x414d6
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
cmpb $0x0, 0x6(%rax)
je 0x2b3c8
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
cmpl $0x1f, %eax
jle 0x2b3d8
xorl %edi, %edi
leaq 0x16118(%rip), %rsi     # 0x414e9
movb $0x0, %al
callq 0x47d0
jmp 0x2b3da
movq -0x10(%rbp), %rax
movzbl 0x7(%rax), %eax
movw %ax, -0x12(%rbp)
movzwl -0x12(%rbp), %ecx
andl $0x80, %ecx
leaq 0x987a(%rip), %rsi      # 0x34c71
leaq 0x4abb(%rip), %rax      # 0x2feb9
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x160ee(%rip), %rdi     # 0x414fa
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x2b44d
movzwl -0x12(%rbp), %ecx
andl $0x40, %ecx
leaq 0x13ed0(%rip), %rsi     # 0x3f2ff
leaq 0x13ecd(%rip), %rax     # 0x3f303
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x160e0(%rip), %rdi     # 0x41524
movb $0x0, %al
callq 0x4050
jmp 0x2b46b
movzwl -0x12(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x2b469
xorl %edi, %edi
leaq 0x160dd(%rip), %rsi     # 0x4153f
movb $0x0, %al
callq 0x47d0
jmp 0x2b46b
leaq 0x160ee(%rip), %rdi     # 0x41560
xorl %eax, %eax
callq 0x4050
movzwl -0x12(%rbp), %eax
shrl $0x4, %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x3, %eax
ja 0x2b4e0
movq -0x40(%rbp), %rax
leaq 0x15cdb(%rip), %rcx     # 0x41174
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x160d1(%rip), %rdi     # 0x4157a
movb $0x0, %al
callq 0x4050
jmp 0x2b4e0
leaq 0x160d0(%rip), %rdi     # 0x41589
movb $0x0, %al
callq 0x4050
jmp 0x2b4e0
leaq 0x160e0(%rip), %rdi     # 0x415a9
movb $0x0, %al
callq 0x4050
jmp 0x2b4e0
leaq 0x160f1(%rip), %rdi     # 0x415ca
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %ecx
andl $0x8, %ecx
leaq 0x16156(%rip), %rsi     # 0x41644
leaq 0x49c4(%rip), %rax      # 0x2feb9
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x160e6(%rip), %rdi     # 0x415e9
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %ecx
andl $0x4, %ecx
leaq 0x16129(%rip), %rsi     # 0x41641
leaq 0x499a(%rip), %rax      # 0x2feb9
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x160d5(%rip), %rdi     # 0x41602
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %ecx
andl $0x2, %ecx
leaq 0x16102(%rip), %rsi     # 0x41644
leaq 0x4970(%rip), %rax      # 0x2feb9
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x160f2(%rip), %rdi     # 0x41649
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2b57a
xorl %edi, %edi
leaq 0x16103(%rip), %rsi     # 0x41676
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
movw %ax, -0x12(%rbp)
leaq 0x1610a(%rip), %rdi     # 0x41697
xorl %eax, %eax
callq 0x4050
movzwl -0x12(%rbp), %eax
movl %eax, -0x44(%rbp)
subl $0x15, %eax
je 0x2b5ca
jmp 0x2b5a2
movl -0x44(%rbp), %eax
subl $0x19, %eax
je 0x2b5da
jmp 0x2b5ac
movl -0x44(%rbp), %eax
subl $0x24, %eax
je 0x2b5ea
jmp 0x2b5b6
movl -0x44(%rbp), %eax
subl $0x48, %eax
je 0x2b5fa
jmp 0x2b5c0
movl -0x44(%rbp), %eax
subl $0x49, %eax
je 0x2b60a
jmp 0x2b61a
leaq 0x160d9(%rip), %rdi     # 0x416aa
movb $0x0, %al
callq 0x4050
jmp 0x2b640
leaq 0x160df(%rip), %rdi     # 0x416c0
movb $0x0, %al
callq 0x4050
jmp 0x2b640
leaq 0x160e7(%rip), %rdi     # 0x416d8
movb $0x0, %al
callq 0x4050
jmp 0x2b640
leaq 0x160fd(%rip), %rdi     # 0x416fe
movb $0x0, %al
callq 0x4050
jmp 0x2b640
leaq 0x16123(%rip), %rdi     # 0x41734
movb $0x0, %al
callq 0x4050
jmp 0x2b640
movzwl -0x12(%rbp), %esi
leaq 0x8c13(%rip), %rdi      # 0x34238
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x1612c(%rip), %rsi     # 0x41765
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x3, %eax
jne 0x2b66a
movzwl -0x12(%rbp), %eax
cmpl $0x48, %eax
je 0x2b66a
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x1611f(%rip), %rsi     # 0x41782
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x2(%rax), %eax
cmpl $0x4, %eax
jne 0x2b694
movzwl -0x12(%rbp), %eax
cmpl $0x49, %eax
je 0x2b694
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x1611e(%rip), %rsi     # 0x417ab
movb $0x0, %al
callq 0x47d0
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
movw %ax, -0x12(%rbp)
cmpw $0x0, -0x12(%rbp)
je 0x2b6da
movzwl -0x12(%rbp), %esi
leaq 0x16122(%rip), %rdi     # 0x417d4
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %eax
cmpl $0xff, %eax
jne 0x2b6d8
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x16137(%rip), %rsi     # 0x41808
movb $0x0, %al
callq 0x47d0
jmp 0x2b6da
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xb(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movw %ax, -0x12(%rbp)
cmpw $0x0, -0x12(%rbp)
je 0x2b72d
movzwl -0x12(%rbp), %esi
leaq 0x1611c(%rip), %rdi     # 0x41821
movb $0x0, %al
callq 0x4050
movzwl -0x12(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x2b72b
movzwl -0x12(%rbp), %edx
xorl %edi, %edi
leaq 0x16131(%rip), %rsi     # 0x41855
movb $0x0, %al
callq 0x47d0
jmp 0x2b72d
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0xd(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movw %ax, -0x12(%rbp)
movzwl -0x12(%rbp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0x2b761
leaq 0x16116(%rip), %rdi     # 0x4186e
movb $0x0, %al
callq 0x4050
jmp 0x2b77c
cmpw $0x0, -0x12(%rbp)
je 0x2b77a
movzwl -0x12(%rbp), %esi
leaq 0x16128(%rip), %rdi     # 0x4189b
movb $0x0, %al
callq 0x4050
jmp 0x2b77c
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)