// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0x204b7c(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x995ac
jmp 0x99a8f
leaq 0x2fcc47(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x995bd
jmp 0x99a8f
movl $0x80000000, %ecx       # imm = 0x80000000
leaq 0x1de4e7(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x99742
leaq 0x301e27(%rip), %rdi    # 0x39b400
leaq 0xeb5d4(%rip), %rsi     # 0x184bb4
movb $0x0, %al
callq 0x9060
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x99607
leaq 0x301e07(%rip), %rdi    # 0x39b400
leaq 0xfd116(%rip), %rsi     # 0x196716
callq 0x96a0
jmp 0x9961a
leaq 0x301df2(%rip), %rdi    # 0x39b400
leaq 0xeab06(%rip), %rsi     # 0x18411b
callq 0x96a0
movl -0x4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x9963a
leaq 0x301dd4(%rip), %rdi    # 0x39b400
leaq 0xfd0e3(%rip), %rsi     # 0x196716
callq 0x96a0
jmp 0x9964d
leaq 0x301dbf(%rip), %rdi    # 0x39b400
leaq 0xeaad3(%rip), %rsi     # 0x18411b
callq 0x96a0
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x996b4
leaq 0x2d3921(%rip), %rax    # 0x36cf80
cmpl $0x57, (%rax)
jne 0x99679
leaq 0x301d95(%rip), %rdi    # 0x39b400
leaq 0xeaaa9(%rip), %rsi     # 0x18411b
callq 0x96a0
jmp 0x996b2
leaq 0x2d3900(%rip), %rax    # 0x36cf80
cmpl $0x2220, (%rax)         # imm = 0x2220
jne 0x9969d
leaq 0x301d71(%rip), %rdi    # 0x39b400
leaq 0xeaa85(%rip), %rsi     # 0x18411b
callq 0x96a0
jmp 0x996b0
leaq 0x301d5c(%rip), %rdi    # 0x39b400
leaq 0xfd06b(%rip), %rsi     # 0x196716
callq 0x96a0
jmp 0x996b2
jmp 0x996c7
leaq 0x301d45(%rip), %rdi    # 0x39b400
leaq 0xeaa59(%rip), %rsi     # 0x18411b
callq 0x96a0
movl -0x4(%rbp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x996e9
leaq 0x301d25(%rip), %rdi    # 0x39b400
leaq 0xfd034(%rip), %rsi     # 0x196716
callq 0x96a0
jmp 0x996fc
leaq 0x301d10(%rip), %rdi    # 0x39b400
leaq 0xeaa24(%rip), %rsi     # 0x18411b
callq 0x96a0
movl -0x4(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x9971e
leaq 0x301cf0(%rip), %rdi    # 0x39b400
leaq 0xfcfff(%rip), %rsi     # 0x196716
callq 0x96a0
jmp 0x99731
leaq 0x301cdb(%rip), %rdi    # 0x39b400
leaq 0xea9ef(%rip), %rsi     # 0x18411b
callq 0x96a0
leaq 0x301cc8(%rip), %rdi    # 0x39b400
callq 0x830d0
jmp 0x99a8a
leaq 0x1de367(%rip), %rax    # 0x277ab0
cmpq $0x800, (%rax)          # imm = 0x800
jne 0x99803
movl -0x4(%rbp), %eax
andl $-0x9, %eax
movl %eax, -0x4(%rbp)
movl $0xd, %edi
callq 0x824f0
movl $0x2, %edi
callq 0x7b210
movb $0x0, -0x5(%rbp)
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x99793
movl -0x4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x99793
movb $0x0, -0x5(%rbp)
jmp 0x997ca
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x997a4
movb $0x1, -0x5(%rbp)
jmp 0x997c8
movl -0x4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x997b5
movb $0x2, -0x5(%rbp)
jmp 0x997c6
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x997c4
movb $0x3, -0x5(%rbp)
jmp 0x997c6
jmp 0x997c8
jmp 0x997ca
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x997d7
jmp 0x997f0
movl -0x4(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x997ee
movzbl -0x5(%rbp), %eax
addl $0xa, %eax
movb %al, -0x5(%rbp)
jmp 0x997f0
movzbl -0x5(%rbp), %edi
callq 0x7b210
callq 0x82630
jmp 0x99a88
leaq 0x1de2a6(%rip), %rax    # 0x277ab0
cmpq $0x4, (%rax)
jne 0x9981f
movl -0x4(%rbp), %edi
xorl %esi, %esi
callq 0x99330
jmp 0x99a86
leaq 0x1de28a(%rip), %rax    # 0x277ab0
cmpq $0x80, (%rax)
jne 0x9992b
movl $0x64, %edi
movl $0x5, %esi
callq 0x84080
movl $0x19, %edi
callq 0x7b210
movl -0x4(%rbp), %eax
andl $0xf, %eax
movzwl %ax, %edi
callq 0x7b4b0
movl $0x1, %edi
callq 0x84130
movl $0x62, %edi
movl $0x5, %esi
callq 0x84080
movl $0x3, %edi
callq 0x7b210
movl -0x4(%rbp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x99896
movl $0x1, %edi
callq 0x7b210
jmp 0x9989d
xorl %edi, %edi
callq 0x7b210
movl $0x1, %edi
callq 0x7b210
movl $0x1, %edi
callq 0x84130
movl $0x62, %edi
movl $0x9, %esi
callq 0x84080
movl $0x1, %edi
callq 0x7b210
movl -0x4(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x998e3
movl $0x1, %edi
callq 0x7b210
jmp 0x998ea
xorl %edi, %edi
callq 0x7b210
movl $0x2, %edi
callq 0x7b210
movl $0x8, %edi
callq 0x7b210
movl $0x1, %edi
callq 0x7b210
movl $0x2, %edi
callq 0x7b210
movl $0xf, %edi
callq 0x7b210
movl $0x1, %edi
callq 0x84130
jmp 0x99a84
leaq 0x1de17e(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x99a82
leaq 0x2047ca(%rip), %rax    # 0x29e10d
cmpb $0x0, (%rax)
jne 0x999b9
leaq 0x1de195(%rip), %rax    # 0x277ae4
movzbl (%rax), %eax
cmpl $0x4, %eax
je 0x999b9
leaq 0x1de152(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9997c
leaq 0x1e0849(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x9997c
leaq 0x1de161(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
je 0x999b9
leaq 0x1de12d(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x99a80
leaq 0x1e0820(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x99a80
leaq 0x1de134(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0x999b9
leaq 0x1de128(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x99a80
leaq 0x136494(%rip), %rax    # 0x1cfe54
movl (%rax), %eax
movl %eax, -0xc(%rbp)
leaq 0x13648c(%rip), %rax    # 0x1cfe58
movl (%rax), %eax
movl %eax, -0x10(%rbp)
leaq 0x136480(%rip), %rax    # 0x1cfe58
movl $0x29a, (%rax)          # imm = 0x29A
movl -0x4(%rbp), %ecx
leaq 0x13646c(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movl $0xff, %edx
movss 0xd7f41(%rip), %xmm3    # 0x171938
movl %edx, %edi
movl %edx, %esi
movaps %xmm3, %xmm0
movaps %xmm3, %xmm1
movaps %xmm3, %xmm2
callq 0x805d0
movl $0x1f4, %edi            # imm = 0x1F4
callq 0xb8b0
leaq 0x13643a(%rip), %rax    # 0x1cfe54
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x99a35
movl $0x3, %edi
movl $0xe, %esi
callq 0x7e6c0
jmp 0x99a68
leaq 0x136418(%rip), %rax    # 0x1cfe54
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x99a57
movl $0x8, %edi
movl $0xf, %esi
callq 0x7e6c0
jmp 0x99a66
movl $0x3, %edi
movl $0x10, %esi
callq 0x7e6c0
jmp 0x99a68
movl -0xc(%rbp), %ecx
leaq 0x1363e2(%rip), %rax    # 0x1cfe54
movl %ecx, (%rax)
movl -0x10(%rbp), %ecx
leaq 0x1363da(%rip), %rax    # 0x1cfe58
movl %ecx, (%rax)
jmp 0x99a82
jmp 0x99a84
jmp 0x99a86
jmp 0x99a88
jmp 0x99a8a
callq 0x90ac0
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)