// File: /workspace/github_cpp_makefile_star2_O1/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
movq 0x38(%r14), %rdx
leaq 0x13d59(%rip), %rcx     # 0x32a19
movl $0x28, %r8d
xorl %esi, %esi
callq 0x3390
movq 0x30(%r14), %rsi
leaq 0x60e3(%rip), %rdi      # 0x24dbb
xorl %eax, %eax
callq 0x3030
movzbl 0x51(%rbx), %eax
movl %eax, %r15d
andl $0x3f, %r15d
shrl $0x6, %eax
leaq 0x12d98(%rip), %rcx     # 0x31a8c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
addq $0x51, %rbx
leaq 0x145fb(%rip), %rdi     # 0x33303
callq 0x3380
movq %rbx, %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
jne 0x1ee4f
leaq 0x13d17(%rip), %rsi     # 0x32a42
jmp 0x1ee61
leal -0x10(%r15), %eax
cmpl $-0x10, %eax
ja 0x1ed4c
leaq 0x13da4(%rip), %rsi     # 0x32ae4
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x37ec
cmpl $0xf, %r15d
movl $0xf, %r14d
cmovbl %r15d, %r14d
leaq 0x13da7(%rip), %rdi     # 0x32b08
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x52(%rbx), %rsi
leaq 0x66cf(%rip), %rdi      # 0x25445
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bbb
leaq (%rbx,%r14), %rdi
addq $0x52, %rdi
movl %r14d, %ebp
xorl $0xf, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
jne 0x1edb5
leal 0x52(%r14), %edx
leaq 0x13cf9(%rip), %rsi     # 0x32aa5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x13d7d(%rip), %rdi     # 0x32b39
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x61(%rbx), %rsi
leaq 0x6674(%rip), %rdi      # 0x25445
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bbb
leaq (%rbx,%r14), %rdi
addq $0x61, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
jne 0x1ee0a
leal 0x61(%r14), %edx
leaq 0x13ca4(%rip), %rsi     # 0x32aa5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x13d5a(%rip), %rdi     # 0x32b6b
movl %r14d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x70(%rbx), %rsi
leaq 0x661f(%rip), %rdi      # 0x25445
movl %r14d, %edx
xorl %ecx, %ecx
movl $0x10, %r8d
callq 0x5bbb
leaq (%rbx,%r14), %rdi
addq $0x70, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
je 0x1eeff
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x13bff(%rip), %rsi     # 0x32a60
xorl %edi, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37ec
leal -0x2e(%r15), %eax
cmpl $-0x2e, %eax
ja 0x1ee90
leaq 0x13c03(%rip), %rsi     # 0x32a87
xorl %edi, %edi
movl %r15d, %edx
xorl %eax, %eax
callq 0x37ec
movl $0x2d, %esi
cmpl %esi, %r15d
cmovael %esi, %r15d
leaq (%rbx,%r15), %rdi
addq $0x52, %rdi
addq $0x52, %rbx
subl %r15d, %esi
xorl %edx, %edx
callq 0x5b92
testb %al, %al
jne 0x1eeca
leal 0x52(%r15), %edx
leaq 0x13be4(%rip), %rsi     # 0x32aa5
xorl %edi, %edi
xorl %eax, %eax
callq 0x37ec
leaq 0x13bf4(%rip), %rdi     # 0x32ac5
movl %r15d, %esi
xorl %eax, %eax
callq 0x3030
leaq 0x6563(%rip), %rdi      # 0x25445
movq %rbx, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movl $0xf, %r8d
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5bbb
orl $0x70, %r14d
leaq 0x13b9b(%rip), %rsi     # 0x32aa5
xorl %edi, %edi
movl %r14d, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x37ec