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

	unsigned char v = x[0x51];
	unsigned num_entries = v & 0x3f;

	switch ((v & 0xc0) >> 6) {
	case 0x00:
		printf("    No Display Transfer Characteristics\n");
		if (!memchk(x + 0x51, 46))
			fail("Bytes 0x51-0x7e should be 0.\n");
		return;
	case 0x03:
		fail("Bits 7-6 of byte 0x51 cannot be 0x03.\n");
		return;
	default:
		break;
	}

	if (((v & 0xc0) >> 6) == 0x01) {
		if (!num_entries || num_entries > 45)
			fail("White Curve with %u entries.\n", num_entries);
		if (num_entries > 45)
			num_entries = 45;
		if (!memchk(x + 0x52 + num_entries, 45 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + num_entries);
		printf("    White Curve (%u entries):\n", num_entries);
		hex_block("      ", x + 0x52, num_entries, false, 15);
	} else {
		if (!num_entries || num_entries > 15)
			fail("Sub-Channel Curve with %u entries.\n", num_entries);
		if (num_entries > 15)
			num_entries = 15;
		printf("    Sub-Channel 0 (Blue) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52, num_entries, false);
		if (!memchk(x + 0x52 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + num_entries);
		printf("    Sub-Channel 1 (Green) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52 + 15, num_entries, false);
		if (!memchk(x + 0x52 + 15 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + 15 + num_entries);
		printf("    Sub-Channel 2 (Red) Curve with %u entries:\n", num_entries);
		hex_block("      ", x + 0x52 + 30, num_entries, false);
		if (!memchk(x + 0x52 + 30 + num_entries, 15 - num_entries))
			fail("Bytes 0x%02x-0x7e should be 0.\n", 0x52 + 30 + num_entries);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x28(%rbp)
leaq 0x15e71(%rip), %rsi     # 0x42904
callq 0x4420
movq -0x28(%rbp), %rdi
callq 0x4150
movq %rax, %rsi
leaq 0x7646(%rip), %rdi      # 0x340f1
xorl %eax, %eax
callq 0x4050
movq -0x10(%rbp), %rax
movb 0x51(%rax), %al
movb %al, -0x11(%rbp)
movzbl -0x11(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x18(%rbp)
movzbl -0x11(%rbp), %eax
shrl $0x6, %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
je 0x2cae0
jmp 0x2cad6
movl -0x1c(%rbp), %eax
subl $0x3, %eax
je 0x2cb1b
jmp 0x2cb30
leaq 0x15e46(%rip), %rdi     # 0x4292d
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rdi
addq $0x51, %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2cb16
xorl %edi, %edi
leaq 0x15e47(%rip), %rsi     # 0x42956
movb $0x0, %al
callq 0x47d0
jmp 0x2cd52
xorl %edi, %edi
leaq 0x15e50(%rip), %rsi     # 0x42974
movb $0x0, %al
callq 0x47d0
jmp 0x2cd52
jmp 0x2cb32
movzbl -0x11(%rbp), %eax
andl $0xc0, %eax
sarl $0x6, %eax
cmpl $0x1, %eax
jne 0x2cbdf
cmpl $0x0, -0x18(%rbp)
je 0x2cb53
cmpl $0x2d, -0x18(%rbp)
jbe 0x2cb66
movl -0x18(%rbp), %edx
xorl %edi, %edi
leaq 0x15e3c(%rip), %rsi     # 0x4299b
movb $0x0, %al
callq 0x47d0
cmpl $0x2d, -0x18(%rbp)
jbe 0x2cb73
movl $0x2d, -0x18(%rbp)
movq -0x10(%rbp), %rdi
addq $0x52, %rdi
movl -0x18(%rbp), %eax
addq %rax, %rdi
movl $0x2d, %esi
subl -0x18(%rbp), %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2cbaa
movl -0x18(%rbp), %edx
addl $0x52, %edx
xorl %edi, %edi
leaq 0x15e16(%rip), %rsi     # 0x429b9
movb $0x0, %al
callq 0x47d0
movl -0x18(%rbp), %esi
leaq 0x15e25(%rip), %rdi     # 0x429d9
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rsi
addq $0x52, %rsi
movl -0x18(%rbp), %edx
leaq 0x7c10(%rip), %rdi      # 0x347dd
xorl %ecx, %ecx
movl $0xf, %r8d
callq 0x7860
jmp 0x2cd52
cmpl $0x0, -0x18(%rbp)
je 0x2cbeb
cmpl $0xf, -0x18(%rbp)
jbe 0x2cbfe
movl -0x18(%rbp), %edx
xorl %edi, %edi
leaq 0x15e01(%rip), %rsi     # 0x429f8
movb $0x0, %al
callq 0x47d0
cmpl $0xf, -0x18(%rbp)
jbe 0x2cc0b
movl $0xf, -0x18(%rbp)
movl -0x18(%rbp), %esi
leaq 0x15e07(%rip), %rdi     # 0x42a1c
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rsi
addq $0x52, %rsi
movl -0x18(%rbp), %edx
leaq 0x7baf(%rip), %rdi      # 0x347dd
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x7860
movq -0x10(%rbp), %rdi
addq $0x52, %rdi
movl -0x18(%rbp), %eax
addq %rax, %rdi
movl $0xf, %esi
subl -0x18(%rbp), %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2cc72
movl -0x18(%rbp), %edx
addl $0x52, %edx
xorl %edi, %edi
leaq 0x15d4e(%rip), %rsi     # 0x429b9
movb $0x0, %al
callq 0x47d0
movl -0x18(%rbp), %esi
leaq 0x15dd1(%rip), %rdi     # 0x42a4d
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rsi
addq $0x52, %rsi
addq $0xf, %rsi
movl -0x18(%rbp), %edx
leaq 0x7b44(%rip), %rdi      # 0x347dd
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x7860
movq -0x10(%rbp), %rdi
addq $0x52, %rdi
addq $0xf, %rdi
movl -0x18(%rbp), %eax
addq %rax, %rdi
movl $0xf, %esi
subl -0x18(%rbp), %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2cce1
movl -0x18(%rbp), %edx
addl $0x61, %edx
xorl %edi, %edi
leaq 0x15cdf(%rip), %rsi     # 0x429b9
movb $0x0, %al
callq 0x47d0
movl -0x18(%rbp), %esi
leaq 0x15d94(%rip), %rdi     # 0x42a7f
movb $0x0, %al
callq 0x4050
movq -0x10(%rbp), %rsi
addq $0x52, %rsi
addq $0x1e, %rsi
movl -0x18(%rbp), %edx
leaq 0x7ad5(%rip), %rdi      # 0x347dd
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x7860
movq -0x10(%rbp), %rdi
addq $0x52, %rdi
addq $0x1e, %rdi
movl -0x18(%rbp), %eax
addq %rax, %rdi
movl $0xf, %esi
subl -0x18(%rbp), %esi
xorl %edx, %edx
callq 0x7810
testb $0x1, %al
jne 0x2cd50
movl -0x18(%rbp), %edx
addl $0x70, %edx
xorl %edi, %edi
leaq 0x15c70(%rip), %rsi     # 0x429b9
movb $0x0, %al
callq 0x47d0
jmp 0x2cd52
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)