// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
addq $0x30, %rdi
leaq 0x13c19(%rip), %rsi     # 0x2ca59
callq 0x3460
movq 0x30(%r14), %rsi
leaq 0x5fbb(%rip), %rdi      # 0x1ee0b
xorl %eax, %eax
callq 0x3030
movzbl 0x51(%rbx), %eax
movl %eax, %r15d
andl $0x3f, %r15d
shrl $0x6, %eax
leaq 0x12c60(%rip), %rcx     # 0x2bacc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq $0x51, %rbx
leaq 0x144c3(%rip), %rdi     # 0x2d343
callq 0x33b0
pushq $0x2e
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x4fa5
testb %al, %al
jne 0x18fbd
leaq 0x13be1(%rip), %rsi     # 0x2ca82
jmp 0x18fcf
leal -0x10(%r15), %eax
cmpl $-0x10, %eax
ja 0x18ec2
leaq 0x13c6e(%rip), %rsi     # 0x2cb24
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x362c
cmpl $0xf, %r15d
pushq $0xf
popq %r14
cmovbl %r15d, %r14d
leaq 0x13c73(%rip), %rdi     # 0x2cb48
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x52(%rbx), %rsi
leaq 0x65ab(%rip), %rdi      # 0x1f495
pushq $0x10
popq %r8
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x4fc1
leaq (%rbx,%r14), %rdi
addq $0x52, %rdi
movl %r14d, %ebp
xorl $0xf, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x4fa5
testb %al, %al
jne 0x18f27
leal 0x52(%r14), %edx
leaq 0x13bc7(%rip), %rsi     # 0x2cae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x13c4b(%rip), %rdi     # 0x2cb79
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x61(%rbx), %rsi
leaq 0x6552(%rip), %rdi      # 0x1f495
pushq $0x10
popq %r8
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x4fc1
leaq (%rbx,%r14), %rdi
addq $0x61, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x4fa5
testb %al, %al
jne 0x18f7a
leal 0x61(%r14), %edx
leaq 0x13b74(%rip), %rsi     # 0x2cae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x13c2a(%rip), %rdi     # 0x2cbab
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x70(%rbx), %rsi
leaq 0x64ff(%rip), %rdi      # 0x1f495
pushq $0x10
popq %r8
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x4fc1
leaq (%rbx,%r14), %rdi
addq $0x70, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x4fa5
testb %al, %al
je 0x19069
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13ad1(%rip), %rsi     # 0x2caa0
xorl %edi, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x362c
leal -0x2e(%r15), %eax
cmpl $-0x2e, %eax
ja 0x18ffe
leaq 0x13ad5(%rip), %rsi     # 0x2cac7
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x362c
pushq $0x2d
popq %rsi
cmpl %esi, %r15d
cmovael %esi, %r15d
leaq (%rbx,%r15), %rdi
addq $0x52, %rdi
addq $0x52, %rbx
subl %r15d, %esi
xorl %edx, %edx
callq 0x4fa5
testb %al, %al
jne 0x19036
leal 0x52(%r15), %edx
leaq 0x13ab8(%rip), %rsi     # 0x2cae5
xorl %edi, %edi
xorl %eax, %eax
callq 0x362c
leaq 0x13ac8(%rip), %rdi     # 0x2cb05
movl %r15d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x6447(%rip), %rdi      # 0x1f495
pushq $0xf
popq %r8
movq %rbx, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4fc1
orl $0x70, %r14d
leaq 0x13a71(%rip), %rsi     # 0x2cae5
xorl %edi, %edi
movl %r14d, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x362c