// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_tsip_config()
void get_tsip_config()
{
u08 rcvr_mode;
u08 rsvd1;
u08 rsvd2;
u08 rsvd3;
u08 rsvd4[32]; 
u08 sat_types;
u08 i, last;
float el_val;
float amu_val;

   log_packet_id("Packet 0xBB (Receiver config)");

   subcode = tsip_byte();       // 0
   rcvr_mode = tsip_byte();     // 1
   rsvd1 = tsip_byte();         // 2
   dynamics_code = tsip_byte(); // 3
   rsvd2 = tsip_byte();         // 4
   el_val = tsip_single();      // 5
   amu_val = tsip_single();     // 9
   pdop_mask = tsip_single();   // 13
   have_pdop_mask |= 0x01;
   pdop_switch = tsip_single(); // 17
   have_pdop_mask |= 0x02;
   rsvd3 = tsip_byte();         // 21  (DGPS age)
   foliage_mode = tsip_byte();  // 22 saw_icm: anti-jam mode

   // byte 23: low power mode
   // byte 24: clock hold mode
   // byte 25: measurement rate
   // byte 26: fix rate
   // byte 27: sat type mask for OD clock mode saw_icm
   //          0x01 GPS
   //          0x02 GLONASS
   //          0x08 Beidou
   //          0x10 Galileo
   //          0x20 QZSS 
   last = 40;
   if(ACU_GG) last = 43;  // !!!!! should be 40, but this causes a packet read error!
   else if(ACU_360) last = 40;
   else if(ACUTIME && (acu_type == '1')) last = 43;  // !!!! 40 for newer models?
   else if(PALISADE) last = 44;

   for(i=23; i<last; i++) {   
      rsvd4[i-23] = tsip_byte();
      if((i == 27) && (saw_icm || (res_t == RES_T_360) || ACU_GG || ACU_360)) { // saw_icm: byte 28 = OD clock mode sat type bit mask
         sat_types = rsvd4[i-23];
         if(sat_types == 0) ;
         else if(sat_types == 0xFF) ;
         else {
            gnss_mask = 0;
            if(sat_types & 0x01) gnss_mask |= GPS;
            if(sat_types & 0x02) gnss_mask |= GLONASS;
            if(sat_types & 0x08) gnss_mask |= BEIDOU;
            if(sat_types & 0x10) gnss_mask |= GALILEO;
            if(sat_types & 0x20) gnss_mask |= QZSS;
            if(gnss_mask == 0) {
               gnss_mask = MIXED;
               have_gnss_mask = 0;
            }
            else have_gnss_mask = 4;
         }
      }
   }

   check_tsip_end(1);

   // stupid filtering required for STARLOC II devices
   el_val = (float) (int) ((el_val*RAD_TO_DEG) + 0.50F);
   if(0 && STARLOC) ;
   else if((el_val >= 0.0) && (el_val <= 90.0)) {
      el_mask = el_val;
      have_el_mask = 1;
   }

   if(0 && STARLOC) ;
   else if((amu_val >= 0.0) && (amu_val < 60.0)) {
      amu_mask = amu_val;
      have_amu = 1;
   }
   if(tsip_error) return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
leaq 0xddbaf(%rip), %rdi     # 0x18559e
callq 0x7add0
callq 0x7a510
movb %al, %cl
leaq 0x1f673c(%rip), %rax    # 0x29e13e
movb %cl, (%rax)
callq 0x7a510
movb %al, -0x1(%rbp)
callq 0x7a510
movb %al, -0x2(%rbp)
callq 0x7a510
movb %al, %cl
leaq 0x2c4883(%rip), %rax    # 0x36c2a5
movb %cl, (%rax)
callq 0x7a510
movb %al, -0x3(%rbp)
callq 0x7a860
movss %xmm0, -0x38(%rbp)
callq 0x7a860
movss %xmm0, -0x3c(%rbp)
callq 0x7a860
leaq 0x2c4850(%rip), %rax    # 0x36c29c
movss %xmm0, (%rax)
leaq 0x2c4855(%rip), %rax    # 0x36c2ac
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2c4849(%rip), %rax    # 0x36c2ac
movl %ecx, (%rax)
callq 0x7a860
leaq 0x2c482f(%rip), %rax    # 0x36c2a0
movss %xmm0, (%rax)
leaq 0x2c4830(%rip), %rax    # 0x36c2ac
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x2c4824(%rip), %rax    # 0x36c2ac
movl %ecx, (%rax)
callq 0x7a510
movb %al, -0x4(%rbp)
callq 0x7a510
movb %al, %cl
leaq 0x2c4804(%rip), %rax    # 0x36c2a4
movb %cl, (%rax)
movb $0x28, -0x33(%rbp)
leaq 0x1d0003(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7ad4
leaq 0x1d26fa(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xa7ad4
leaq 0x1d0012(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0xa7ad4
movb $0x2b, -0x33(%rbp)
jmp 0xa7b59
leaq 0x1cffd5(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7b0b
leaq 0x1d26cc(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xa7b0b
leaq 0x1cffe4(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0xa7b05
leaq 0x1cffd8(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0xa7b0b
movb $0x28, -0x33(%rbp)
jmp 0xa7b57
leaq 0x1cff9e(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7b36
leaq 0x1d2695(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xa7b36
leaq 0x1cffad(%rip), %rax    # 0x277ad8
cmpl $0x31, (%rax)
jne 0xa7b36
movb $0x2b, -0x33(%rbp)
jmp 0xa7b55
leaq 0x1cff73(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7b53
leaq 0x1d266a(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0xa7b53
movb $0x2c, -0x33(%rbp)
jmp 0xa7b55
jmp 0xa7b57
jmp 0xa7b59
movb $0x17, -0x32(%rbp)
movzbl -0x32(%rbp), %eax
movzbl -0x33(%rbp), %ecx
cmpl %ecx, %eax
jge 0xa7d38
callq 0x7a510
movb %al, %cl
movzbl -0x32(%rbp), %eax
subl $0x17, %eax
cltq
movb %cl, -0x30(%rbp,%rax)
movzbl -0x32(%rbp), %eax
cmpl $0x1b, %eax
jne 0xa7d29
leaq 0x1f6578(%rip), %rax    # 0x29e10d
cmpb $0x0, (%rax)
jne 0xa7c0b
leaq 0x1cff43(%rip), %rax    # 0x277ae4
movzbl (%rax), %eax
cmpl $0x4, %eax
je 0xa7c0b
leaq 0x1cff00(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7bce
leaq 0x1d25f7(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xa7bce
leaq 0x1cff0f(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
je 0xa7c0b
leaq 0x1cfedb(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0xa7d29
leaq 0x1d25ce(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0xa7d29
leaq 0x1cfee2(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0xa7c0b
leaq 0x1cfed6(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0xa7d29
movzbl -0x32(%rbp), %eax
subl $0x17, %eax
cltq
movb -0x30(%rbp,%rax), %al
movb %al, -0x31(%rbp)
movzbl -0x31(%rbp), %eax
cmpl $0x0, %eax
jne 0xa7c29
jmp 0xa7d27
movzbl -0x31(%rbp), %eax
cmpl $0xff, %eax
jne 0xa7c39
jmp 0xa7d25
leaq 0x128214(%rip), %rax    # 0x1cfe54
movl $0x0, (%rax)
movzbl -0x31(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xa7c67
leaq 0x1281fb(%rip), %rax    # 0x1cfe54
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x1281ef(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movzbl -0x31(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xa7c88
leaq 0x1281da(%rip), %rax    # 0x1cfe54
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x1281ce(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movzbl -0x31(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xa7ca9
leaq 0x1281b9(%rip), %rax    # 0x1cfe54
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x1281ad(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movzbl -0x31(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xa7cca
leaq 0x128198(%rip), %rax    # 0x1cfe54
movl (%rax), %ecx
orl $0x4, %ecx
leaq 0x12818c(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movzbl -0x31(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0xa7cee
leaq 0x128177(%rip), %rax    # 0x1cfe54
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
leaq 0x128168(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
leaq 0x12815f(%rip), %rax    # 0x1cfe54
cmpl $0x0, (%rax)
jne 0xa7d16
leaq 0x128153(%rip), %rax    # 0x1cfe54
movl $0xc00f, (%rax)         # imm = 0xC00F
leaq 0x12814a(%rip), %rax    # 0x1cfe58
movl $0x0, (%rax)
jmp 0xa7d23
leaq 0x12813b(%rip), %rax    # 0x1cfe58
movl $0x4, (%rax)
jmp 0xa7d25
jmp 0xa7d27
jmp 0xa7d29
jmp 0xa7d2b
movb -0x32(%rbp), %al
addb $0x1, %al
movb %al, -0x32(%rbp)
jmp 0xa7b5d
movl $0x1, %edi
callq 0x7aee0
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xc742d(%rip), %xmm1    # 0x16f180
mulsd %xmm1, %xmm0
movsd 0xc7331(%rip), %xmm1    # 0x16f090
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
cvtsi2ss %eax, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa7db6
movss -0x38(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xc72f5(%rip), %xmm0    # 0x16f088
ucomisd %xmm1, %xmm0
jb 0xa7db6
movss -0x38(%rbp), %xmm0
leaq 0x2c44ef(%rip), %rax    # 0x36c294
movss %xmm0, (%rax)
leaq 0x2c482c(%rip), %rax    # 0x36c5dc
movl $0x1, (%rax)
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa7dfc
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0xc723f(%rip), %xmm0    # 0x16f018
ucomisd %xmm1, %xmm0
jbe 0xa7dfc
movss -0x3c(%rbp), %xmm0
leaq 0x2c44ad(%rip), %rax    # 0x36c298
movss %xmm0, (%rax)
leaq 0x2c47e2(%rip), %rax    # 0x36c5d8
movl $0x1, (%rax)
leaq 0x1f634d(%rip), %rax    # 0x29e150
cmpl $0x0, (%rax)
je 0xa7e0a
jmp 0xa7e0a
addq $0x40, %rsp
popq %rbp
retq