// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
cmpl $0xa, 0x48(%rdi)
jne 0x60b4
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movss (%rax), %xmm0
movss 0x4(%rax), %xmm1
addss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0xb28d(%rip), %xmm1     # 0x111b0
cvtss2sd 0x1e0(%rdi), %xmm2
ucomisd %xmm1, %xmm2
ja 0x60b4
cvtss2sd %xmm0, %xmm1
mulsd 0xb277(%rip), %xmm1     # 0x111b8
movss 0x188(%rbx), %xmm0
cvtss2sd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
ja 0x60b4
movss 0x140(%rbx), %xmm1
ucomiss 0x184(%rbx), %xmm1
jb 0x60b4
mulss 0xb5ec(%rip), %xmm0     # 0x11560
movss %xmm0, 0xe8(%rbx)
cvtss2sd %xmm0, %xmm1
cvtss2sd 0x180(%rbx), %xmm0
mulsd 0xb1e8(%rip), %xmm0     # 0x11178
ucomisd %xmm1, %xmm0
jbe 0x5fa2
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%rbx)
andw $0x0, 0xa0(%rbx)
pushq $0xf
popq %rdx
cmpq $-0x1, %rdx
je 0x5fdf
movss 0x8(%rax,%rdx,4), %xmm0
ucomiss 0xe8(%rbx), %xmm0
jbe 0x5fda
movl %edx, %ecx
andb $0x7, %cl
movb $-0x80, %sil
shrb %cl, %sil
movl %edx, %ecx
shrl $0x3, %ecx
addb %sil, 0xa0(%rbx,%rcx)
decq %rdx
jmp 0x5fad
pushq $0x4
popq %r14
pushq $0x8
popq %rdx
movq %rbx, %rdi
movl %r14d, %esi
callq 0xeb6a
movl %eax, %ecx
shrl $0x2, %ecx
movl %eax, %edx
subl %ecx, %edx
movl %eax, %ecx
shrl $0x4, %ecx
leal (%rcx,%rcx,8), %ecx
addl %edx, %ecx
movl %eax, %edx
shrl $0x6, %edx
leal (%rdx,%rdx,2), %edx
addl %ecx, %edx
movzbl 0xa1(%rbx), %ecx
andl $0xf, %ecx
andl $0xf, %edx
cmpl %ecx, %edx
jne 0x60b4
movl $0xb, 0x88(%rbx)
movzbl 0xa0(%rbx), %ecx
shrl $0x4, %ecx
movq 0x160(%rbx), %rdx
movl %ecx, (%rdx)
movq 0x170(%rbx), %rcx
movl %eax, (%rcx)
movq 0x178(%rbx), %rcx
movl %eax, (%rcx)
movq 0x148(%rbx), %rax
movabsq $0x56546365726944, %rcx # imm = 0x56546365726944
movq %rcx, (%rax)
movb 0xf2bc(%rip), %al       # 0x15328
testb %al, %al
je 0x60b9
movl 0xf2ae(%rip), %eax      # 0x15324
andl $0x1, %eax
movl 0x2c(%rbx), %ecx
xorl %edx, %edx
cmpl $0x9859, %ecx           # imm = 0x9859
setl %dl
addl %edx, %edx
cmpl $0xbb81, %ecx           # imm = 0xBB81
cmovgel %r14d, %edx
orl %eax, %edx
movl %edx, 0xf289(%rip)      # 0x15324
movq 0x150(%rbx), %rdi
leaq 0xbf34(%rip), %rsi      # 0x11fdd
xorl %eax, %eax
popq %rbx
popq %r14
popq %rbp
jmp 0x2060
popq %rbx
popq %r14
popq %rbp
retq
leaq 0xf268(%rip), %rdi      # 0x15328
callq 0x2250
testl %eax, %eax
je 0x6070
movq 0x40(%rbx), %rax
movss (%rax), %xmm0
xorl %eax, %eax
ucomiss 0xb48a(%rip), %xmm0     # 0x11564
seta %al
movl %eax, 0xf241(%rip)      # 0x15324
leaq 0xf23e(%rip), %rdi      # 0x15328
callq 0x20d0
jmp 0x6070