// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: set_gnss_system(int)
void set_gnss_system(int system)
{
u08 val;
int old_gnss_mask;
int old_have_gnss;

   // set the GNSS system/systems to use
   if(luxor) return;
   if(read_only) return;
//sprintf(plot_title, "GNSS set rcvr:%04X gnss:%04X", rcvr_type, system);

   if(rcvr_type == ESIP_RCVR) {
      sprintf(out, "PERDAPI,GNSS,AUTO");
      if(system & GPS) strcat(out, ",2");
      else             strcat(out, ",0");
      if(system & GLONASS) strcat(out, ",2");
      else                 strcat(out, ",0");
      if(system & GALILEO) {
         if(furuno_type == 87)        strcat(out, ",0");
         else if(furuno_type == 8736) strcat(out, ",0");
         else                         strcat(out, ",2");
      }
      else                 strcat(out, ",0");
      if(system & QZSS) strcat(out, ",2");
      else              strcat(out, ",0");
      if(system & SBAS) strcat(out, ",2");
      else              strcat(out, ",0");
      send_esip_cmd(out);
   }
   else if(rcvr_type == NVS_RCVR) {
      system &= (~BEIDOU);
      send_nvs_start(0x0D);
      send_byte(0x02);
      val = 0;
      if((system & GPS) && (system & GLONASS)) val = 0;
      else if(system & GPS) val = 1;
      else if(system & GLONASS) val = 2;
      else if(system & GALILEO) val = 3;
      if(system & GALILEO) ;            // can't do SBAS
      else if(system & SBAS) val += 10; // include SBAS 
      send_byte(val);
      send_nvs_end();
   }
   else if(rcvr_type == UBX_RCVR) {
      set_ubx_gnss(system, 0);
   }
   else if(rcvr_type == VENUS_RCVR) {
      send_venus_start(SET_VENUS_GNSS);
      send_byte(0x19);
      send_word((u16) (system & (GPS | GLONASS | BEIDOU | GALILEO)));
      send_venus_save(1);

      send_venus_start(SET_VENUS_QZSS);
      send_byte(0x03);
      if(system & QZSS) send_byte(1);
      else              send_byte(0);
      send_byte(1);       // channels
      send_venus_save(1);

if(1) {
      send_venus_start(SET_VENUS_SBAS);
      send_byte(0x01);
      if(system & SBAS) send_byte(1);
      else              send_byte(0);
      send_byte(2);     // auto select mode
      send_byte(8);     // URA
      send_byte(1);     // apply corrections
      send_byte(2);     // channels
      send_byte(0x0F);  // WAAS + EGNOS + MSAS + GAGAN
      send_venus_save(1);
}
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(saw_icm || (res_t == RES_T_360) || ACU_GG || ACU_360) {
         old_gnss_mask = gnss_mask;
         old_have_gnss = have_gnss_mask;
         have_gnss_mask = 666;
         gnss_mask = system;

         set_config(0xFF, 0xFF, -1.0F, -1.0F, -1.0F, -1.0F, 0xFF);
Sleep(500);
if(gnss_mask & GPS)          set_timing_mode(TMODE_UTC, 14);
else if(gnss_mask & GLONASS) set_timing_mode(TMODE_GLONASS, 15);
else                         set_timing_mode(TMODE_UTC, 16);

         gnss_mask = old_gnss_mask;
         have_gnss_mask = old_have_gnss;
      }
   }

   request_gnss_system();
}

// Assembly:
leaq 0x1cea8f(%rip), %rax    # 0x23ef3e
leaq 0x2c6b64(%rip), %rcx    # 0x33701a
movb (%rcx), %cl
orb (%rax), %cl
jne 0x70539
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x1a83fd(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x7f, %rax
jle 0x7053a
cmpq $0x80, %rax
je 0x7055c
cmpq $0x800, %rax            # imm = 0x800
je 0x70656
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
jne 0x7085e
movups 0xb141f(%rip), %xmm0    # 0x121924
leaq 0x2cbd14(%rip), %r14    # 0x33c220
movaps %xmm0, (%r14)
movw $0x4f, 0x10(%r14)
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x1, %bl
jne 0x7076f
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70778
retq
cmpq $0x1, %rax
je 0x706bb
cmpq $0x4, %rax
jne 0x7085e
movl %ebx, %edi
xorl %esi, %esi
callq 0x7031f
jmp 0x7085e
movl $0x64, %edi
movl $0x5, %esi
callq 0x5fb3c
movl $0x19, %edi
callq 0x590f7
movl %ebx, %eax
andl $0xf, %eax
movw %ax, -0x2a(%rbp)
leaq 0x1a824f(%rip), %r14    # 0x2187d4
xorl %eax, %eax
cmpb $0x0, (%r14)
sete %al
movzbl -0x2a(%rbp,%rax), %edi
callq 0x590f7
xorl %eax, %eax
cmpb $0x0, (%r14)
setne %al
movzbl -0x2a(%rbp,%rax), %edi
callq 0x590f7
movl $0x1, %edi
callq 0x5fc00
movl $0x62, %edi
movl $0x5, %esi
callq 0x5fb3c
movl $0x3, %edi
callq 0x590f7
movl %ebx, %edi
shrl $0xe, %edi
andl $0x1, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x5fc00
movl $0x62, %edi
movl $0x9, %esi
callq 0x5fb3c
movl $0x1, %edi
callq 0x590f7
shrl $0xf, %ebx
andl $0x1, %ebx
movl %ebx, %edi
callq 0x590f7
movl $0x2, %edi
callq 0x590f7
movl $0x8, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x590f7
movl $0x2, %edi
callq 0x590f7
movl $0xf, %edi
callq 0x590f7
movl $0x1, %edi
callq 0x5fc00
jmp 0x7085e
movl $0xd, %edi
callq 0x5e6be
movl $0x2, %r14d
movl $0x2, %edi
callq 0x590f7
movl %ebx, %eax
andl $0x3, %eax
xorl %ecx, %ecx
cmpl $0x3, %eax
setne %cl
testb $0x1, %bl
cmovel %r14d, %ecx
xorl %edx, %edx
testb $0x4, %bl
setne %dl
testl %eax, %eax
leal (%rdx,%rdx,2), %eax
cmovnel %ecx, %eax
andl $0x8004, %ebx           # imm = 0x8004
leal 0xa(%rax), %ecx
cmpl $0x8000, %ebx           # imm = 0x8000
movzbl %cl, %ecx
cmovnel %eax, %ecx
movzbl %cl, %edi
callq 0x590f7
callq 0x5e7c0
jmp 0x7085e
leaq 0x1ce86b(%rip), %rax    # 0x23ef2d
cmpb $0x0, (%rax)
jne 0x706f7
leaq 0x1a8236(%rip), %rax    # 0x218904
cmpb $0x4, (%rax)
je 0x706f7
leaq 0x1aa8fa(%rip), %rax    # 0x21afd4
movl (%rax), %ecx
movl %ecx, %edx
xorl $0x41, %edx
leaq 0x1a8210(%rip), %rax    # 0x2188f8
movl (%rax), %eax
movl %eax, %esi
xorl $0x47, %esi
orl %edx, %esi
jne 0x707e7
leaq 0x100576(%rip), %r14    # 0x170c74
movl (%r14), %r15d
leaq 0x100570(%rip), %r12    # 0x170c78
movl (%r12), %r13d
movl $0x29a, (%r12)          # imm = 0x29A
movl %ebx, (%r14)
movss 0x9c949(%rip), %xmm0    # 0x10d068
movl $0xff, %edi
movl $0xff, %esi
movaps %xmm0, %xmm1
movaps %xmm0, %xmm2
movaps %xmm0, %xmm3
movl $0xff, %edx
callq 0x5cf59
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xafe8
movl (%r14), %eax
xorl %ecx, %ecx
testb $0x2, %al
setne %cl
testb $0x1, %al
leal 0x3(%rcx,%rcx,4), %eax
movl $0x3, %edi
cmovel %eax, %edi
callq 0x5b96d
movl %r15d, (%r14)
movl %r13d, (%r12)
jmp 0x7085e
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testb $0x2, %bl
jne 0x70793
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x7079c
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
testb $0x4, %bl
jne 0x707b8
movq %r14, %rdi
callq 0x9120
movw $0x302c, (%r14,%rax)    # imm = 0x302C
movb $0x0, 0x2(%r14,%rax)
jmp 0x70809
leaq 0x29d5e1(%rip), %rax    # 0x30dda0
movl (%rax), %r15d
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
cmpl $0x2220, %r15d          # imm = 0x2220
je 0x707dc
cmpl $0x57, %r15d
jne 0x70800
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70809
cmpl $0x41, %ecx
jne 0x7085e
cmpl $0x47, %eax
je 0x706f7
cmpl $0x33, %eax
je 0x706f7
jmp 0x7085e
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
btl $0xe, %ebx
jb 0x70825
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x7082e
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
movq %r14, %rdi
callq 0x9120
addq %r14, %rax
testw %bx, %bx
js 0x70849
movb $0x0, 0x2(%rax)
movw $0x302c, (%rax)         # imm = 0x302C
jmp 0x70852
movb $0x0, 0x2(%rax)
movw $0x322c, (%rax)         # imm = 0x322C
leaq 0x2cb9c7(%rip), %rdi    # 0x33c220
callq 0x5ee9b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6a236