// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x48(%rdi), %eax
cmpl $0xc, %eax
je 0x462a
cmpl $0xa, %eax
jne 0x488b
movss 0x184(%rbx), %xmm2
movss 0x1dc(%rbx), %xmm1
ucomiss %xmm2, %xmm1
jae 0x488b
ucomiss 0xcec2(%rip), %xmm1     # 0x1150c
ja 0x488b
movss 0x1d0(%rbx), %xmm0
movss 0xcea8(%rip), %xmm3     # 0x11508
mulss %xmm0, %xmm3
movss 0xce94(%rip), %xmm4     # 0x11500
mulss %xmm1, %xmm4
ucomiss %xmm3, %xmm4
jae 0x488b
cvtss2sd %xmm0, %xmm3
movsd 0xcac3(%rip), %xmm4     # 0x11148
ucomisd %xmm3, %xmm4
ja 0x488b
movss 0x13c(%rbx), %xmm3
ucomiss %xmm2, %xmm3
movq 0x38(%rbx), %rax
jae 0x46cd
ucomiss -0x8(%rax), %xmm1
jbe 0x46cd
movq 0x8(%rbx), %rcx
movslq 0x20(%rbx), %rdx
leaq (%rcx,%rdx,8), %rsi
cmpq %rsi, %rax
jne 0x488b
movslq 0x24(%rbx), %rsi
addq %rdx, %rsi
ucomiss -0x8(%rcx,%rsi,8), %xmm1
ja 0x488b
xorps %xmm1, %xmm1
movups %xmm1, 0xa0(%rbx)
movq %rax, 0xc8(%rbx)
andq $0x0, 0xc0(%rbx)
divss 0xce06(%rip), %xmm0     # 0x114f4
movss %xmm0, 0xe8(%rbx)
pushq $0xb
popq %rsi
movq %rbx, %rdi
callq 0xece0
movzbl 0xa0(%rbx), %r15d
andl $0x3f, %r15d
cmpl $0xc, 0x48(%rbx)
jne 0x479c
testb $0x1, %r15b
je 0x488b
movl %r15d, %eax
bswapl %eax
movl %eax, %ecx
andl $0xc000000, %ecx        # imm = 0xC000000
movl %eax, %edx
shll $0x4, %edx
shrl $0x4, %eax
andl $0x3000000, %eax        # imm = 0x3000000
orl %edx, %eax
shll $0x2, %eax
leal (%rax,%rcx,4), %eax
movl %eax, %ecx
andl $0x54000000, %ecx       # imm = 0x54000000
shrl %eax
andl $0x55555540, %eax       # imm = 0x55555540
leal (%rax,%rcx,2), %eax
shrl $0x18, %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
shrl %r15d
pushq $0x6
popq %rsi
pushq $0x5
popq %rdx
movq %rbx, %rdi
callq 0xebd6
addl %r15d, %eax
cmpl $0x1f, %eax
jne 0x488b
movq 0x148(%rbx), %rax
movl $0x303158, (%rax)       # imm = 0x303158
movq 0x170(%rbx), %rax
movl %r15d, (%rax)
xorl %eax, %eax
jmp 0x4888
movq 0x148(%rbx), %r14
pushq $0x5
popq %rsi
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0xebd6
bswapl %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl $0xf0f0f0f, %edx        # imm = 0xF0F0F0F
andl %edx, %ecx
andl %edx, %eax
shll $0x4, %eax
orl %ecx, %eax
movl $0x33333333, %ecx       # imm = 0x33333333
movl %eax, %edx
andl %ecx, %edx
shrl $0x2, %eax
andl %ecx, %eax
leal (%rax,%rdx,4), %eax
movl $0x50000000, %ecx       # imm = 0x50000000
movl %eax, %edx
andl %ecx, %edx
shrl %eax
andl %ecx, %eax
leal (%rax,%rdx,2), %edx
shrl $0x1c, %edx
leaq 0xd6bb(%rip), %rsi      # 0x11eac
movq %r14, %rdi
xorl %eax, %eax
callq 0x2060
andl $0x1f, %r15d
movq 0x170(%rbx), %rax
movl %r15d, (%rax)
leal 0x1(,%r15,2), %eax
bswapl %eax
movl %eax, %ecx
shll $0x4, %ecx
movl %eax, %edx
shrl $0x4, %edx
andl $0x3000000, %edx        # imm = 0x3000000
orl %ecx, %edx
andl $0x33303030, %edx       # imm = 0x33303030
shll $0x2, %edx
andl $0xc000000, %eax        # imm = 0xC000000
leal (%rdx,%rax,4), %eax
movl $0x54404040, %ecx       # imm = 0x54404040
movl %eax, %edx
andl %ecx, %edx
shrl %eax
andl %ecx, %eax
leal (%rax,%rdx,2), %eax
shrl $0x18, %eax
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
movabsq $0x500000000, %rax      # imm = 0x500000000
movq %rax, 0x88(%rbx)
movq 0x150(%rbx), %rax
movabsq $0x2064696c61766e69, %rcx # imm = 0x2064696C61766E69
movq %rcx, (%rax)
movabsq $0x6c616e67697320, %rcx # imm = 0x6C616E67697320
movq %rcx, 0x7(%rax)
pushq $0x1
popq %rax
movl %eax, 0x70(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq