// File: probonopd[P]decodeir/DecodeIR.cpp
// Function: DecodeIR
void DecodeIR_API DecodeIR
(	unsigned int* Context,		//In/Out - Array of unsigned 4 byte integers.  For input it tells dll in what context it should 
								//decode the signal, and on output the context it would need to decode the next part of the signal.
								//It has a minimum length of 2, and on first call, both integers are 0.  Further information can
								//be passed in either direction by increasing its length.  See TiSubDevice below.
	int* TpaiBursts, 			//In - Array of integers containing the burst lengths in microseconds, 
								//the length of the array is 2*(TiSingleBurstCount + TiRepeatBurstCount +
								//ExtraBurstCount), where ExtraBurstCount is carried in TiDevice, see below.
	int TiFreq,					//In - Frequency in Hz of the signal.  Use -1 for unknown.  Any positive
								//   value less than 500000/longest_on will be treated as unmodulated, but
								//   normally unmodulated should be represented as 0.
	int TiSingleBurstCount,		//In - Number of bursts sent once
	int TiRepeatBurstCount,		//In - Number of bursts sent repeatedly

	// For all int* outputs, the caller must preset the value to -1 and the decoder will not change the value
	//   unless it finds a decode and that decode includes that value.
	// Similarly char* outputs should have their first byte set to 0 by the caller and the decoder will
	//   overwrite with a null terminated string only when that string is not empty.
	char* TsProtocol,			//Out - 255 character string name of the decoded protocol
	int* TiDevice,				//Out - Integer device number.
								//In  - If < -1 and RepeatBurstCount > 0, it is -ExtraBurstCount.  If < -1
								//and RepeatBurstCount = 0 it flags that the frame count should not be returned
								//to the caller.  The caller should include any extra bursts in with the single
								//bursts in this case.  All versions of IR.exe have done this.
	int* TiSubDevice,			//Out - Integer sub device number.
								//In  - If < -1 it is negative of the length of the Context array.  A handshake
								//protocol is used to return to the caller the actual length that has been
								//interpreted and acted upon by the version of DecodeIR in use.  This version
								//supports a maximum length of 9.  See decode2() for more details.
	int* TiOBC,					//Out - Integer OBC of the decoded signal
	int* TaiHex,				//Out - Array of 4 integers containing up to 4 different one-byte Hex commands
								//if returning less that 4 hex values, the remaining integers should be -1
	char* TsMisc,				//Out - 255 character string of Misc text, used whenever more explanation of 
								//the results should be returned
	char* TsError)				//Out - 255 character string containing an error message if the dll encountered an error
{
	if (TiSingleBurstCount + TiRepeatBurstCount >= MinFrame)
	{
		char szMessage[500];
		sprintf(szMessage,"N=%d SCount=%d RCount=%d Burst1=%d Freq=%d hex[0]=%d Error=\"%s\""
			,*Context, TiSingleBurstCount, TiRepeatBurstCount, TpaiBursts[1],TiFreq,TaiHex[-1],TsError);
		//	MessageBox(0,szMessage,"DecodeIR",0);
		Signal _Signal(
			Context,
			TpaiBursts, 	
			TiFreq, 
			TiSingleBurstCount, 
			TiRepeatBurstCount, 
			TsProtocol, 
			TiDevice, 
			TiSubDevice, 
			TiOBC, 
			TaiHex, 
			TsMisc, 
			TsError );

		_Signal.decode2();	// GD 2009 changed from decode()
	}
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x460, %rsp            # imm = 0x460
movq 0x38(%rbp), %rax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movl %edx, -0x34(%rbp)
movl %ecx, -0x38(%rbp)
movl %r8d, -0x3c(%rbp)
movq %r9, -0x48(%rbp)
movl -0x38(%rbp), %eax
addl -0x3c(%rbp), %eax
cmpl $0x2, %eax
jl 0x17aaf
movq -0x28(%rbp), %rax
movl (%rax), %edx
movl -0x38(%rbp), %ecx
movl -0x3c(%rbp), %r8d
movq -0x30(%rbp), %rax
movl 0x4(%rax), %r9d
movl -0x34(%rbp), %esi
movq 0x28(%rbp), %rax
movl -0x4(%rax), %edi
movq 0x38(%rbp), %r10
movq %rsp, %rax
movq %r10, 0x10(%rax)
movl %edi, 0x8(%rax)
movl %esi, (%rax)
leaq 0x37c0(%rip), %rsi      # 0x1b1c5
xorl %eax, %eax
leaq -0x240(%rbp), %rdi
callq 0x2060
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %r8d
movl -0x3c(%rbp), %r9d
movq -0x48(%rbp), %rdi
movq 0x10(%rbp), %r10
movq 0x18(%rbp), %r11
movq 0x20(%rbp), %rbx
movq 0x28(%rbp), %r14
movq 0x30(%rbp), %r15
movq 0x38(%rbp), %r12
movq %rsp, %rax
movq %r12, 0x30(%rax)
movq %r15, 0x28(%rax)
movq %r14, 0x20(%rax)
movq %rbx, 0x18(%rax)
movq %r11, 0x10(%rax)
movq %r10, 0x8(%rax)
movq %rdi, (%rax)
leaq -0x428(%rbp), %rdi
movq %rdi, -0x440(%rbp)
callq 0x23a0
movq -0x440(%rbp), %rdi
callq 0x14990
jmp 0x17a81
leaq -0x428(%rbp), %rdi
callq 0x27a0
jmp 0x17aaf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x430(%rbp)
movl %eax, -0x434(%rbp)
leaq -0x428(%rbp), %rdi
callq 0x27a0
jmp 0x17abf
addq $0x460, %rsp            # imm = 0x460
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq -0x430(%rbp), %rdi
callq 0x2220
nopl (%rax,%rax)