// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: set_ubx_gnss(int, int)
void set_ubx_gnss(int system, int save)
{
int id;
int min_chans;
int max_chans;
int min_chan_count;
int max_chan_count;
u32 flags;

   if(read_only) return;

   send_ubx_start(UBX_GNSS, 4+NUM_UBX_SYS*8);
   send_byte((u08) 0);
   send_byte((u08) 32);
   send_byte((u08) 0xFF);
   send_byte((u08) NUM_UBX_SYS);

   min_chan_count = max_chan_count = 0;
   for(id=0; id<NUM_UBX_SYS; id++) {
      flags = 0x01010000;
      min_chans = 0;
      max_chans = 0;
      if(id == 0) {       // GPS
         if(system & GPS) {
            flags |= 0x00000001;
            min_chans = 8;   // 8;
            max_chans = 16;  // 16;
         }
      }
      else if(id == 1) {  // SBAS
         if(system & SBAS) {
            flags |= 0x00000001;
            min_chans = 1;
            max_chans = 3;
         }
      }
      else if(id == 2) {  // GALILEO
         if(system & GALILEO) {
            flags |= 0x00000001;
            min_chans = 4;    // 4;
            max_chans = 8;   // 8;
         }
      }
      else if(id == 3) {  // Beidou
         if(system & BEIDOU) {
            flags |= 0x00000001;
            min_chans = 8;    // 8;
            max_chans = 16;   // 16;
         }
      }
      else if(id == 4) {  // IMES
         if(system & IMES) {
            flags |= 0x00000001;
            flags |= 0x02000000;
            min_chans = 0;
            max_chans = 8;   // 8;
         }
      }
      else if(id == 5) {  // QZSS
         if(system & QZSS) {
            flags |= 0x00000001;
            flags |= 0x04000000;
            min_chans = 0;
            max_chans = 3;
         }
      }
      else if(id == 6) {  // GLONASS
         if(system & GLONASS) {
            flags |= 0x0001;
            min_chans = 8;  // 8;
            max_chans = 14; // 14;
         }
      }

      min_chan_count += min_chans;
      max_chan_count += max_chans;

      send_byte((u08) id);
      send_byte((u08) min_chans);
      send_byte((u08) max_chans);
      send_byte((u08) 0); // reserved
      send_dword(flags);
   }

   send_ubx_end();
Sleep(1000);
//sprintf(debug_text, "GNSS set gnss %04X: min:%d  max:%d", system, min_chan_count,max_chan_count);
   if(save) save_segment(6, 28);  // save PPS timing config in EEPROM
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x2ba487(%rip), %rax    # 0x32101a
cmpb $0x0, (%rax)
je 0x66ba7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %edi, %ebx
movl %esi, -0x30(%rbp)
pushq $0x3c
popq %rsi
movl $0x63e, %edi            # imm = 0x63E
callq 0x57bf3
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x523f2
pushq $0x20
popq %rdi
callq 0x523f2
movl $0xff, %edi
callq 0x523f2
pushq $0x7
popq %rdi
callq 0x523f2
xorl %eax, %eax
btl $0xe, %ebx
setb %al
movl $0x1010000, %ecx        # imm = 0x1010000
movl $0x5010001, %edx        # imm = 0x5010001
cmovael %ecx, %edx
movl %edx, -0x38(%rbp)
movl %ebx, -0x2c(%rbp)
andl $0x2000, %ebx           # imm = 0x2000
movl %ebx, %esi
shrl $0xa, %esi
testl %ebx, %ebx
movl $0x3010001, %ebx        # imm = 0x3010001
cmovel %ecx, %ebx
leal (%rax,%rax,2), %eax
movl %eax, -0x34(%rbp)
xorl %r15d, %r15d
movl %r14d, %eax
leaq 0xa21d7(%rip), %r12     # 0x108df8
movslq (%r12,%rax,4), %rax
addq %r12, %rax
movl %esi, %r13d
movl %ebx, %r8d
movl %esi, -0x3c(%rbp)
jmpq *%rax
xorl %r15d, %r15d
testb $0x1, -0x2c(%rbp)
je 0x66c7f
movl $0x1010001, %r8d        # imm = 0x1010001
movb $0x10, %r13b
jmp 0x66cab
xorl %r15d, %r15d
cmpw $0x0, -0x2c(%rbp)
jns 0x66c7f
movl $0x1010001, %r8d        # imm = 0x1010001
movb $0x3, %r13b
movb $0x1, %r15b
jmp 0x66cae
xorl %r15d, %r15d
testb $0x4, -0x2c(%rbp)
je 0x66c7f
movl $0x1010001, %r8d        # imm = 0x1010001
movb $0x8, %r13b
movb $0x4, %r15b
jmp 0x66cae
xorl %r15d, %r15d
testb $0x8, -0x2c(%rbp)
jne 0x66c3c
xorl %r13d, %r13d
movl $0x1010000, %r8d        # imm = 0x1010000
jmp 0x66cae
xorl %r15d, %r15d
movl -0x34(%rbp), %r13d
movl -0x38(%rbp), %r8d
jmp 0x66cae
testb $0x2, -0x2c(%rbp)
jne 0x66ca2
xorl %r15d, %r15d
jmp 0x66c7f
movl $0x1010001, %r8d        # imm = 0x1010001
movb $0xe, %r13b
movb $0x8, %r15b
movl %r14d, -0x40(%rbp)
movzbl %r14b, %edi
movl %r8d, %r14d
callq 0x523f2
movzbl %r15b, %edi
callq 0x523f2
movzbl %r13b, %edi
callq 0x523f2
xorl %edi, %edi
callq 0x523f2
movl %r14d, %edi
callq 0x525e2
movl -0x3c(%rbp), %esi
movl -0x40(%rbp), %r14d
incl %r14d
xorl %r15d, %r15d
movl %r14d, %eax
movslq (%r12,%rax,4), %rax
addq %r12, %rax
movl %esi, %r13d
movl %ebx, %r8d
jmpq *%rax
callq 0x57cca
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xae83
cmpl $0x0, -0x30(%rbp)
je 0x66b98
pushq $0x6
popq %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6166c