// File: /workspace/github_cpp_makefile_star2_O3/probonopd[P]decodeir/DecodeIR.cpp
// Function: Signal::tryDirecTV()
void Signal::tryDirecTV()
{
	// PID 0162
	// GD:  The representation as 
	// {38.4k,601}<1,-1|1,-2|2,-1|2,-2>(10,-2,(D:4,F:8,C:4,1,-50,5,-2)+)
	// is missing "msb" and the freq of the 0162 executor is actually 38.1k.
	// A better representation is
	// {38k,600,msb}<1,-1|1,-2|2,-1|2,-2>(5,(5,-2,D:4,F:8,C:4,1,-50)+)
	// C = 7*(F:2:6)+5*(F:2:4)+3*(F:2:2)+(F:2)
	// since the final 5,-2 is not sent after the final leadout
	// Variants are freq = 38k, 40k or 57k, leadout = -50 or -15
	if (nFrameL != 10)
		return;
    if ( (pFrame[0]+pFrame[1]) * .66 < sortBurst.max2 )
        return;
    if ( pFrame[0] * .75 < sortOn.max2 )
        return;
//	if ( ! framed(sortBurst.max1 * 2) )
//  GD Above statement does not hold for first frame when leadout is -15
//  as then sortBurst.max1 = 12 and frame = 15.  We can weaken this without causing
//  problems since the checksum will rule out spurious decodes.  Note sortOn.max1 = 10.
	if ( ! framed(sortOn.max1 ) )
		return;

    nMaxShort = sortOn.max2 * .75;
    if ( nMaxShort < sortOn.min1 * 1.5 )
        nMaxShort = sortOn.min1 * 1.5;
    cBits[0] = cBits[1] = 0;
	// fill cBits left to right in order of bits received
    for (int ndx=16; --ndx >= 0; )
    {
        if ( pFrame[2+ndx] > nMaxShort )
            cBits[ndx>>3] += 0x80 >> (ndx & 7);
    }
    int cmd = getMsb(4,8);	// this corresponds to msb ordering
    int check = cmd - (cmd>>2) - 7*(cmd>>4) - 13*(cmd>>6);
    
    if ( getMsb(12,4) == (check&15) )
    {
		nNote_out = 11;
	    *pDevice = getMsb(0,4);
	    *pOBC = cmd;
	    *pHex = cmd;
        strcpy(pProtocol, "DirecTV");

		// Report short/long lead-out based only on first frame, since final frame
		// will always have a long lead-out.  Use of static variabl achieves this.  
		static int parm = (*pFrameEnd > 20000);
		parm &= 1;
		parm |= nFreq > 48000 ? 4 : nFreq > 39000 ? 0 : 2;
		sprintf(pMisc, "Parm = %d", parm);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
cmpl $0xa, 0x48(%rdi)
jne 0x6593
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movss (%rax), %xmm0
movss 0x4(%rax), %xmm1
addss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0xbd24(%rip), %xmm1     # 0x121b0
cvtss2sd 0x1e0(%rdi), %xmm2
ucomisd %xmm1, %xmm2
ja 0x6593
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
mulsd 0xbd0b(%rip), %xmm1     # 0x121b8
movss 0x188(%rbx), %xmm0
xorps %xmm2, %xmm2
cvtss2sd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x6593
movss 0x140(%rbx), %xmm1
ucomiss 0x184(%rbx), %xmm1
jb 0x6593
mulss 0xc07d(%rip), %xmm0     # 0x12560
movss %xmm0, 0xe8(%rbx)
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtss2sd 0x180(%rbx), %xmm0
mulsd 0xbc73(%rip), %xmm0     # 0x12178
ucomisd %xmm1, %xmm0
jbe 0x6517
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%rbx)
movw $0x0, 0xa0(%rbx)
movl $0xf, %edx
movss 0x8(%rax,%rdx,4), %xmm0
ucomiss 0xe8(%rbx), %xmm0
jbe 0x654c
movl %edx, %ecx
andb $0x7, %cl
movb $-0x80, %sil
shrb %cl, %sil
movl %edx, %ecx
shrl $0x3, %ecx
addb %sil, 0xa0(%rbx,%rcx)
addq $-0x1, %rdx
jb 0x6525
movzbl 0xa0(%rbx), %eax
movl %eax, %ecx
shll $0x4, %ecx
movzbl %cl, %edx
movzbl 0xa1(%rbx), %esi
movl %esi, %edi
shrl $0x4, %edi
leal (%rdi,%rdx), %ecx
movl %ecx, %r8d
shrl $0x2, %r8d
leal (%rax,%rax,8), %r9d
shrl $0x6, %edx
leal (%rdx,%rdx,2), %edx
addl %edi, %r9d
subl %r8d, %r9d
addl %edx, %r9d
xorl %esi, %r9d
testb $0xf, %r9b
je 0x659a
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movl $0xb, 0x88(%rbx)
shrl $0x4, %eax
movq 0x160(%rbx), %rdx
movl %eax, (%rdx)
movq 0x170(%rbx), %rax
movl %ecx, (%rax)
movq 0x178(%rbx), %rax
movl %ecx, (%rax)
movq 0x148(%rbx), %rax
movabsq $0x56546365726944, %rcx # imm = 0x56546365726944
movq %rcx, (%rax)
movb 0xfd3c(%rip), %al       # 0x16318
testb %al, %al
je 0x662b
movl 0xfd2e(%rip), %eax      # 0x16314
andl $0x1, %eax
movl 0x2c(%rbx), %ecx
xorl %esi, %esi
cmpl $0x9859, %ecx           # imm = 0x9859
setl %sil
addl %esi, %esi
cmpl $0xbb81, %ecx           # imm = 0xBB81
movl $0x4, %edx
cmovll %esi, %edx
orl %eax, %edx
movl %edx, 0xfd04(%rip)      # 0x16314
movq 0x150(%rbx), %rdi
leaq 0xc9bf(%rip), %rsi      # 0x12fdd
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x2060
movq %rbx, %rdi
callq 0x2260
jmp 0x65e0
nop