// File: 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
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $0xa, 0x48(%rax)
je 0x837f
jmp 0x865e
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
movss (%rcx), %xmm0
movq 0x38(%rax), %rcx
addss 0x4(%rcx), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x11f68(%rip), %xmm0    # 0x1a308
mulsd %xmm0, %xmm1
movss 0x1e0(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x83bb
jmp 0x865e
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
movss (%rcx), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x11f3d(%rip), %xmm0    # 0x1a310
mulsd %xmm0, %xmm1
movss 0x188(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x83ee
jmp 0x865e
movq -0x20(%rbp), %rdi
movss 0x184(%rdi), %xmm0
callq 0x18840
cmpl $0x0, %eax
jne 0x8409
jmp 0x865e
movq -0x20(%rbp), %rax
movss 0x188(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x11eef(%rip), %xmm1    # 0x1a310
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%rax)
movss 0xe8(%rax), %xmm0
cvtss2sd %xmm0, %xmm1
movss 0x180(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x11e3f(%rip), %xmm2    # 0x1a290
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0x8483
movq -0x20(%rbp), %rax
movss 0x180(%rax), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x11e1d(%rip), %xmm1    # 0x1a290
mulsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0xe8(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0xa1(%rax)
movb $0x0, 0xa0(%rax)
movl $0x10, -0xc(%rbp)
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, %eax
jl 0x84f6
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rcx
movl -0xc(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movss (%rcx,%rdx,4), %xmm0
ucomiss 0xe8(%rax), %xmm0
jbe 0x84f4
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
andl $0x7, %ecx
movl $0x80, %esi
sarl %cl, %esi
movl -0xc(%rbp), %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movzbl 0xa0(%rax,%rcx), %edx
addl %esi, %edx
movb %dl, 0xa0(%rax,%rcx)
jmp 0x849c
movq -0x20(%rbp), %rdi
movl $0x4, %esi
movl $0x8, %edx
callq 0x15f50
movq -0x20(%rbp), %rdi
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl -0x10(%rbp), %ecx
sarl $0x2, %ecx
subl %ecx, %eax
movl -0x10(%rbp), %ecx
sarl $0x4, %ecx
imull $0x7, %ecx, %ecx
subl %ecx, %eax
movl -0x10(%rbp), %ecx
sarl $0x6, %ecx
imull $0xd, %ecx, %ecx
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl $0xc, %esi
movl $0x4, %edx
callq 0x15f50
movl -0x14(%rbp), %ecx
andl $0xf, %ecx
cmpl %ecx, %eax
jne 0x865e
movq -0x20(%rbp), %rdi
movl $0xb, 0x88(%rdi)
xorl %esi, %esi
movl $0x4, %edx
callq 0x15f50
movl %eax, %edx
movq -0x20(%rbp), %rax
movq 0x160(%rax), %rcx
movl %edx, (%rcx)
movl -0x10(%rbp), %edx
movq 0x170(%rax), %rcx
movl %edx, (%rcx)
movl -0x10(%rbp), %edx
movq 0x178(%rax), %rcx
movl %edx, (%rcx)
movq 0x148(%rax), %rdi
leaq 0x1231f(%rip), %rsi     # 0x1a8bf
callq 0x2120
cmpb $0x0, 0x16d74(%rip)     # 0x1f320
jne 0x85f0
leaq 0x16d6b(%rip), %rdi     # 0x1f320
callq 0x2240
cmpl $0x0, %eax
je 0x85f0
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movss (%rax), %xmm0
movss 0x11aa9(%rip), %xmm1    # 0x1a07c
ucomiss %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x16d34(%rip)     # 0x1f318
leaq 0x16d35(%rip), %rdi     # 0x1f320
callq 0x20d0
movq -0x20(%rbp), %rax
movl 0x16d1e(%rip), %ecx     # 0x1f318
andl $0x1, %ecx
movl %ecx, 0x16d15(%rip)     # 0x1f318
cmpl $0xbb80, 0x2c(%rax)     # imm = 0xBB80
jle 0x8616
movl $0x4, %eax
movl %eax, -0x24(%rbp)
jmp 0x8630
movq -0x20(%rbp), %rax
movl 0x2c(%rax), %edx
movl $0x2, %eax
xorl %ecx, %ecx
cmpl $0x9858, %edx           # imm = 0x9858
cmovgl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movl -0x24(%rbp), %ecx
orl 0x16cdb(%rip), %ecx     # 0x1f318
movl %ecx, 0x16cd5(%rip)     # 0x1f318
movq 0x150(%rax), %rdi
movl 0x16cc8(%rip), %edx     # 0x1f318
leaq 0x12ab9(%rip), %rsi     # 0x1b110
movb $0x0, %al
callq 0x2060
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)