// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryRC6()
void Signal::tryRC6()
//
// {36k,444,msb}<-1,1|1,-1>(6,-2,1:1,M:3,<-2,2|2,-2>(T:1),D:8,F:8,^107m)+		RC6 when M=0
// {36k,444,msb}<-1,1|1,-1>(6,-2,1:1,M:3,<-2,2|2,-2>(T:1),D:8,S:8,F:8,^??)+		Replay when M=6
// {36k,444,msb}<-1,1|1,-1>(6,-2,1:1,M:3,-2,2,OEM1:8,OEM2:8,T:1,D:7,F:8,-69m)+   MCE when M=6, OEM1=128
// {36k,444,msb}<-1,1|1,-1>(6,-2,~M:1:3,M:3,<-2,2|2,-2>(T:1),?:?,^??)+          Unknown versions of RC6
//
{
	if ( nFrameL < 10 )
		return;
	const float HB = 444;
	if (   nMaxDur != *pFrame || nMaxDur < 2*HB || nMaxDur > 12*HB	// First ON nominally 6 half bits
		|| *pFrameEnd < 20*HB )
	{
		return;
	}
	cleanup();
	++pBit;	// Skip over nominal 6
    minGlitch = HB*.25;
	do
	{
		switch (nBit)	// Various boundaries within the sequence
		{
		case 0:  // Lead in Bit inverted treated as extra mode bit
			nMinShort = HB;					// Nominally 2
			nMaxShort = nMinLong = HB*2.5;	// 2 vs. 3
			nMaxLong = HB*3.5;				// Nominally 3
			nMinShort2 = HB*.5;				// Nominally 1
			nMaxShort2 = HB*1.5;			// Nominally 1
			break;
		case 1:  // First true mode bit
			nState = 1 - nState;			// Lead bit was processed with reversed polarity
			nMinShort = HB*.5;				// Nominally 1
			nMaxShort = nMinLong = HB*1.5;	// 1 vs. 2
			nMaxLong = HB*2.5;				// Nominally 2
			break;
		case 4:  // Toggle bit
			nBit = 8;						// Put toggle bit in second byte
			nMaxShort = nMinLong = HB*2.;	// 1 vs. 3
			nMaxLong = HB*3.5;				// Nominally 3
			nMinShort2 = HB;				// Nominally 2
			nMaxShort2 = HB*2.5;			// Nominally 2
			break;
		case 9:  // Bit after Toggle bit
			nBit = 16;						// Put in third byte
			nMinShort = HB;					// Nominally 2
			nMaxShort = nMinLong = HB*2.5;	// 2 vs. 3
			nMaxLong = HB*3.5;				// Nominally 3
			nMinShort2 = HB*.5;				// Nominally 1
			nMaxShort2 = HB*1.5;			// Nominally 1
			break;
		case 17:  // Start of normal section
			nMinShort = HB*.5;				// Nominally 1
			nMaxShort = nMinLong = HB*1.5;	// 1 vs. 2
			nMaxLong = HB*2.5;				// Nominally 2
			break;
		case sizeof(cBits)*8:
			return;
		}
		if ( ! phaseBit() )
			return;
	} while (pBit < pFrameEnd);
	if (nBit < 24)
		return;	// Got too little to be right

	makeMsb();
	cBits[0] >>= 4;

	*pOBC = getMsb(nBit-8, 8);

	if (   nBit == 48
		&& cBits[0] == 6
		&& cBits[2] == 128
		&& ! ( cBits[1] & 128 ) )
	{
		sprintf(pMisc, "T=%d", cBits[4]>>7);
		*pDevice = getMsb(33, 7);
		*pSubDevice = getMsb(24, 8);    // OEM2 reported as subdevice
		pHex[0] = *pOBC;
		strcpy(pProtocol, "MCE");
		return;
	}

	sprintf(pMisc, "T=%d", cBits[1]>>7);

	if (nBit > 24)
	{
		*pDevice = cBits[2];
		if (nBit < 32)
			*pDevice = getMsb(16, nBit-16);
	}
	if (nBit == 32 && cBits[0] == 0)
	{
		pHex[0] = *pOBC;
		strcpy(pProtocol, "RC6");
		return;
	}
	if (nBit > 32)
	{
		*pSubDevice = getMsb(24, nBit-32);
	}
	if (nBit == 40 && cBits[0]==6 ) 
	{
		pHex[0] = *pOBC;
		strcpy(pProtocol, "Replay");
		return;
	}
	if ( preemptValue >= prRCx )		// GD 2009  Avoids spurious decode of OrtekMCE
	{
		return;
	}
	sprintf(pProtocol, "RC6-%d-%d",cBits[0], nBit-16);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0xa, 0x48(%rax)
jge 0x1022f
jmp 0x107d1
movq -0x18(%rbp), %rax
movss 0x9ed9(%rip), %xmm0     # 0x1a114
movss %xmm0, -0xc(%rbp)
movss 0x9c(%rax), %xmm0
movq 0x38(%rax), %rax
ucomiss (%rax), %xmm0
jne 0x10296
jp 0x10296
movq -0x18(%rbp), %rax
movss 0x9eb9(%rip), %xmm0     # 0x1a118
ucomiss 0x9c(%rax), %xmm0
ja 0x10296
movq -0x18(%rbp), %rax
movss 0x9c(%rax), %xmm0
movss 0x9ea0(%rip), %xmm1     # 0x1a11c
ucomiss %xmm1, %xmm0
ja 0x10296
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movss 0x9e8f(%rip), %xmm0     # 0x1a120
ucomiss (%rax), %xmm0
jbe 0x1029b
jmp 0x107d1
movq -0x18(%rbp), %rdi
callq 0x16180
movq -0x18(%rbp), %rax
movq 0xc8(%rax), %rcx
addq $0x4, %rcx
movq %rcx, 0xc8(%rax)
movss 0x9e62(%rip), %xmm0     # 0x1a124
movss %xmm0, 0xe0(%rax)
movq -0x18(%rbp), %rax
movl 0xc0(%rax), %eax
movl %eax, -0x1c(%rbp)
testl %eax, %eax
je 0x10328
jmp 0x102dd
movl -0x1c(%rbp), %eax
subl $0x1, %eax
je 0x10391
jmp 0x102eb
movl -0x1c(%rbp), %eax
subl $0x4, %eax
je 0x103eb
jmp 0x102f9
movl -0x1c(%rbp), %eax
subl $0x9, %eax
je 0x1044e
jmp 0x10307
movl -0x1c(%rbp), %eax
subl $0x11, %eax
je 0x104be
jmp 0x10315
movl -0x1c(%rbp), %eax
subl $0x80, %eax
je 0x10504
jmp 0x10509
movq -0x18(%rbp), %rax
movss 0x9de0(%rip), %xmm0     # 0x1a114
movss %xmm0, 0xe4(%rax)
movss 0x9de4(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xec(%rax)
movss 0x9dd4(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xe8(%rax)
movss 0x9dd0(%rip), %xmm0     # 0x1a134
movss %xmm0, 0xf0(%rax)
movss 0x9dbc(%rip), %xmm0     # 0x1a130
movss %xmm0, 0xf4(%rax)
movss 0x9da8(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xf8(%rax)
jmp 0x10509
movq -0x18(%rbp), %rax
movl $0x1, %ecx
subl 0xc4(%rax), %ecx
movl %ecx, 0xc4(%rax)
movss 0x9d82(%rip), %xmm0     # 0x1a130
movss %xmm0, 0xe4(%rax)
movss 0x9d6e(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xec(%rax)
movss 0x9d5e(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xe8(%rax)
movss 0x9d4a(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xf0(%rax)
jmp 0x10509
movq -0x18(%rbp), %rax
movl $0x8, 0xc0(%rax)
movss 0x9d17(%rip), %xmm0     # 0x1a118
movss %xmm0, 0xec(%rax)
movss 0x9d07(%rip), %xmm0     # 0x1a118
movss %xmm0, 0xe8(%rax)
movss 0x9d13(%rip), %xmm0     # 0x1a134
movss %xmm0, 0xf0(%rax)
movss 0x9ce3(%rip), %xmm0     # 0x1a114
movss %xmm0, 0xf4(%rax)
movss 0x9ce7(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xf8(%rax)
jmp 0x10509
movq -0x18(%rbp), %rax
movl $0x10, 0xc0(%rax)
movss 0x9cb0(%rip), %xmm0     # 0x1a114
movss %xmm0, 0xe4(%rax)
movss 0x9cb4(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xec(%rax)
movss 0x9ca4(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xe8(%rax)
movss 0x9ca0(%rip), %xmm0     # 0x1a134
movss %xmm0, 0xf0(%rax)
movss 0x9c8c(%rip), %xmm0     # 0x1a130
movss %xmm0, 0xf4(%rax)
movss 0x9c78(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xf8(%rax)
jmp 0x10509
movq -0x18(%rbp), %rax
movss 0x9c66(%rip), %xmm0     # 0x1a130
movss %xmm0, 0xe4(%rax)
movss 0x9c52(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xec(%rax)
movss 0x9c42(%rip), %xmm0     # 0x1a12c
movss %xmm0, 0xe8(%rax)
movss 0x9c2e(%rip), %xmm0     # 0x1a128
movss %xmm0, 0xf0(%rax)
jmp 0x10509
jmp 0x107d1
movq -0x18(%rbp), %rdi
callq 0x17050
cmpl $0x0, %eax
jne 0x1051c
jmp 0x107d1
jmp 0x1051e
movq -0x18(%rbp), %rcx
movq 0xc8(%rcx), %rax
cmpq 0x40(%rcx), %rax
jb 0x102ca
movq -0x18(%rbp), %rax
cmpl $0x18, 0xc0(%rax)
jge 0x10545
jmp 0x107d1
movq -0x18(%rbp), %rdi
callq 0x16110
movq -0x18(%rbp), %rdi
movzbl 0xa0(%rdi), %eax
sarl $0x4, %eax
movb %al, 0xa0(%rdi)
movl 0xc0(%rdi), %esi
subl $0x8, %esi
movl $0x8, %edx
callq 0x15f50
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x170(%rax), %rcx
movl %edx, (%rcx)
cmpl $0x30, 0xc0(%rax)
jne 0x10661
movq -0x18(%rbp), %rax
movzbl 0xa0(%rax), %eax
cmpl $0x6, %eax
jne 0x10661
movq -0x18(%rbp), %rax
movzbl 0xa2(%rax), %eax
cmpl $0x80, %eax
jne 0x10661
movq -0x18(%rbp), %rax
movzbl 0xa1(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x10661
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rdi
movzbl 0xa4(%rax), %edx
sarl $0x7, %edx
leaq 0xa9bc(%rip), %rsi      # 0x1afac
movb $0x0, %al
callq 0x2060
movq -0x18(%rbp), %rdi
movl $0x21, %esi
movl $0x7, %edx
callq 0x15f50
movq -0x18(%rbp), %rdi
movl %eax, %ecx
movq 0x160(%rdi), %rax
movl %ecx, (%rax)
movl $0x18, %esi
movl $0x8, %edx
callq 0x15f50
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x168(%rax), %rcx
movl %edx, (%rcx)
movq 0x170(%rax), %rcx
movl (%rcx), %edx
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movq 0x148(%rax), %rdi
leaq 0xa7d7(%rip), %rsi      # 0x1ae2e
callq 0x2120
jmp 0x107d1
movq -0x18(%rbp), %rax
movq 0x150(%rax), %rdi
movzbl 0xa1(%rax), %edx
sarl $0x7, %edx
leaq 0xa92f(%rip), %rsi      # 0x1afac
movb $0x0, %al
callq 0x2060
movq -0x18(%rbp), %rax
cmpl $0x18, 0xc0(%rax)
jle 0x106d6
movq -0x18(%rbp), %rax
movzbl 0xa2(%rax), %edx
movq 0x160(%rax), %rcx
movl %edx, (%rcx)
cmpl $0x20, 0xc0(%rax)
jge 0x106d4
movq -0x18(%rbp), %rdi
movl 0xc0(%rdi), %edx
subl $0x10, %edx
movl $0x10, %esi
callq 0x15f50
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq 0x160(%rax), %rax
movl %ecx, (%rax)
jmp 0x106d6
movq -0x18(%rbp), %rax
cmpl $0x20, 0xc0(%rax)
jne 0x10721
movq -0x18(%rbp), %rax
movzbl 0xa0(%rax), %eax
cmpl $0x0, %eax
jne 0x10721
movq -0x18(%rbp), %rax
movq 0x170(%rax), %rcx
movl (%rcx), %edx
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movq 0x148(%rax), %rdi
leaq 0xa6fd(%rip), %rsi      # 0x1ae14
callq 0x2120
jmp 0x107d1
movq -0x18(%rbp), %rax
cmpl $0x20, 0xc0(%rax)
jle 0x10754
movq -0x18(%rbp), %rdi
movl 0xc0(%rdi), %edx
subl $0x20, %edx
movl $0x18, %esi
callq 0x15f50
movl %eax, %ecx
movq -0x18(%rbp), %rax
movq 0x168(%rax), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
cmpl $0x28, 0xc0(%rax)
jne 0x1079c
movq -0x18(%rbp), %rax
movzbl 0xa0(%rax), %eax
cmpl $0x6, %eax
jne 0x1079c
movq -0x18(%rbp), %rax
movq 0x170(%rax), %rcx
movl (%rcx), %edx
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movq 0x148(%rax), %rdi
leaq 0xa683(%rip), %rsi      # 0x1ae18
callq 0x2120
jmp 0x107d1
movq -0x18(%rbp), %rax
cmpl $0x3, 0x54(%rax)
jl 0x107a8
jmp 0x107d1
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rdi
movzbl 0xa0(%rax), %edx
movl 0xc0(%rax), %ecx
subl $0x10, %ecx
leaq 0xa655(%rip), %rsi      # 0x1ae1f
movb $0x0, %al
callq 0x2060
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)