// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryX10()
void Signal::tryX10()
{
	// <2,-13|7,-7>(8,-8, F:5, ~F:5, 23,-8)+

	// GD 2009: That IRP is only the second part of the protocol that is decoded here.
	// A more complete description is
	// <2,-13|7,-7>(8,-8,F:5,N:-4,23,-8,(8,-8, F:5, ~F:5, 23,-8)+)
	// where N is a 4-bit counter (incremented at each keypress, though that doesn't
	// show in the decode).  However, according to the UEI executor for
	// the X10 protocol, PID 003F, the start frame should not have the (8,-8) 
	// leadin, so that frame is not picked up.  In addition, the UEI timing
	// is slightly different, which may be for convenience but it means that
	// the repeat frame of the UEI executor is also often not picked up.  UEI uses
	//
	// {40.8k,565}<2,-12|7,-7>(F:5,N:-4,21,-7,(7,-7,F:5,~F:5,21,-7)+).
	//
	// This has all bursts of equal length while the IRP above has the lead-in burst
	// being the longest.  The decode tests whether the lead-in is the longest
	// burst and random variations in the UEI execution mean that is often is not, so
	// the frame is missed.  I have removed this test, corrected the start frame and
	// added a test on burst lengths that allows that the (8,-8) lead-in may be correct.

//	if ( nFrameL > 12 || nFrameL < 11 )
	if ( nFrameL != 12 && nFrameL != 10 )		// GD 2009
		return;
	if ( sortOn.max1 <= sortBurst.max1 )	// leadOutOn should exceed sortBurst.max1
		return;
	/*  GD 2009 Allow for all bursts to have same nominal length, so next condition
		removed and following one modified
	if ( pFrame[0]+pFrame[1] <= sortBurst.max2 )
		return;
	*/
	if ( sortBurst.min1*5 <= /* sortBurst.max2*4 */ sortBurst.max1*4 )
		return;
	// GD 2009 Test burst lengths
	if ( sortBurst.min1 < 0.8*14*565 || sortBurst.max1 > 1.2*16*565 )
		return;
	if ( !framedLeft(sortOn.max1) )
		if ( pFrame[-2] < sortBurst.max1 )
			if (   pFrame != pDuration+2*nSingle
				|| pDuration[2*(nSingle+nRepeat)-2] < sortBurst.max1 )
					return;
	cleanup();
	nMaxShort = sortBurst.min1/3;
	decodeX(11);
	int obc = /* getLsb(1,5); */ getLsb(0,6);	// GD 2009 Covers both frame situations
	if ( nFrameL == 12 )
	{
		if ( (obc & 1) != 1 )					// GD 2009 Test lead-in bit 
			return;
		pHex[0] = msb(obc);					// GD 2009 Lead-in 1-bit is included in hex
		obc >>= 1;							// GD 2009 Remove lead-in bit
		if ( getLsb(6,5) + obc != 31 )
			return;
		strcpy(pProtocol,"X10");
		*pOBC = obc;
		bInitLeadIn = false;				// GD 2009
		return;
	}
	sprintf(pProtocol,"X10:%d", msb( getLsb(/* 6 */ 5,4), 4) );
	obc &= 0x1F;							// GD 2009 Remove spurious 6th bit
	*pOBC = obc;	
	pHex[0] = msb(obc<<1 | 1);				// GD 2009 Lead-in 1-bit must be included in hex
	nNote_out = 0;
	nAuxNote_out = 5;
	strcpy(pMisc, "invalid signal");
	bInitLeadIn = true;						// GD 2009
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0xc, 0x48(%rax)
je 0x5eb9
movq -0x18(%rbp), %rax
cmpl $0xa, 0x48(%rax)
je 0x5eb9
jmp 0x6152
movq -0x18(%rbp), %rax
movss 0x184(%rax), %xmm1
movss 0x1dc(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x5ed7
jmp 0x6152
movq -0x18(%rbp), %rax
movss 0x1413d(%rip), %xmm1    # 0x1a020
mulss 0x1d0(%rax), %xmm1
movss 0x14125(%rip), %xmm0    # 0x1a018
mulss 0x1dc(%rax), %xmm0
ucomiss %xmm1, %xmm0
jb 0x5f05
jmp 0x6152
movq -0x18(%rbp), %rax
movss 0x1d0(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x14333(%rip), %xmm0    # 0x1a250
ucomisd %xmm1, %xmm0
ja 0x5f41
movq -0x18(%rbp), %rax
movss 0x1dc(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1431d(%rip), %xmm1    # 0x1a258
ucomisd %xmm1, %xmm0
jbe 0x5f46
jmp 0x6152
movq -0x18(%rbp), %rdi
movss 0x184(%rdi), %xmm0
callq 0x18ac0
cmpl $0x0, %eax
jne 0x5fc7
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
movss -0x8(%rcx), %xmm1
movss 0x1dc(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x5fc5
movq -0x18(%rbp), %rdx
movq 0x38(%rdx), %rax
movq 0x8(%rdx), %rcx
movl 0x20(%rdx), %edx
shll %edx
movslq %edx, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jne 0x5fbe
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movl 0x20(%rax), %edx
addl 0x24(%rax), %edx
shll %edx
subl $0x2, %edx
movslq %edx, %rdx
movss (%rcx,%rdx,4), %xmm1
movss 0x1dc(%rax), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x5fc3
jmp 0x6152
jmp 0x5fc5
jmp 0x5fc7
movq -0x18(%rbp), %rdi
callq 0x16180
movq -0x18(%rbp), %rdi
movss 0x1d0(%rdi), %xmm0
movss 0x14040(%rip), %xmm1    # 0x1a024
divss %xmm1, %xmm0
movss %xmm0, 0xe8(%rdi)
movl $0xb, %esi
callq 0x161d0
movq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x6, %edx
callq 0x16030
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, -0xc(%rbp)
cmpl $0xc, 0x48(%rax)
jne 0x60a4
movl -0xc(%rbp), %eax
andl $0x1, %eax
cmpl $0x1, %eax
je 0x602d
jmp 0x6152
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %esi
movl $0x8, %edx
callq 0x15e70
movq -0x18(%rbp), %rdi
movl %eax, %ecx
movq 0x178(%rdi), %rax
movl %ecx, (%rax)
movl -0xc(%rbp), %eax
sarl %eax
movl %eax, -0xc(%rbp)
movl $0x6, %esi
movl $0x5, %edx
callq 0x16030
addl -0xc(%rbp), %eax
cmpl $0x1f, %eax
je 0x6071
jmp 0x6152
movq -0x18(%rbp), %rax
movq 0x148(%rax), %rdi
leaq 0x14823(%rip), %rsi     # 0x1a8a6
callq 0x2120
movq -0x18(%rbp), %rax
movl -0xc(%rbp), %edx
movq 0x170(%rax), %rcx
movl %edx, (%rcx)
movl $0x0, 0x70(%rax)
jmp 0x6152
movq -0x18(%rbp), %rdi
movq 0x148(%rdi), %rax
movq %rax, -0x20(%rbp)
movl $0x5, %esi
movl $0x4, %edx
callq 0x16030
movq -0x18(%rbp), %rdi
movl %eax, %esi
movl $0x4, %edx
callq 0x15e70
movq -0x20(%rbp), %rdi
movl %eax, %edx
leaq 0x14ef4(%rip), %rsi     # 0x1afd3
movb $0x0, %al
callq 0x2060
movq -0x18(%rbp), %rdi
movl -0xc(%rbp), %eax
andl $0x1f, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %ecx
movq 0x170(%rdi), %rax
movl %ecx, (%rax)
movl -0xc(%rbp), %esi
shll %esi
orl $0x1, %esi
movl $0x8, %edx
callq 0x15e70
movl %eax, %edx
movq -0x18(%rbp), %rax
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movl $0x0, 0x88(%rax)
movl $0x5, 0x8c(%rax)
movq 0x150(%rax), %rdi
leaq 0x14e98(%rip), %rsi     # 0x1afda
callq 0x2120
movq -0x18(%rbp), %rax
movl $0x1, 0x70(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)