// File: /workspace/github_cpp_makefile_star2_O1/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:
leaq 0x2c6de9(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
je 0x70237
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edi, %ebx
movl %esi, -0x30(%rbp)
movl $0x63e, %edi            # imm = 0x63E
movl $0x3c, %esi
callq 0x5f3f5
xorl %r12d, %r12d
xorl %edi, %edi
callq 0x591af
movl $0x20, %edi
callq 0x591af
movl $0xff, %edi
callq 0x591af
movl $0x7, %edi
callq 0x591af
xorl %eax, %eax
btl $0xe, %ebx
setb %al
leal (%rax,%rax,2), %eax
movl %eax, -0x40(%rbp)
movl $0x1010000, %eax        # imm = 0x1010000
movl $0x5010001, %ecx        # imm = 0x5010001
cmovael %eax, %ecx
movl %ecx, -0x3c(%rbp)
movl %ebx, -0x2c(%rbp)
andl $0x2000, %ebx           # imm = 0x2000
movl %ebx, %edx
shrl $0xa, %edx
movl %edx, -0x38(%rbp)
testl %ebx, %ebx
movl $0x3010001, %ecx        # imm = 0x3010001
cmovel %eax, %ecx
movl %ecx, -0x34(%rbp)
leaq 0xaeb30(%rip), %r13     # 0x11edf8
cmpl $0x6, %r12d
ja 0x70339
movl %r12d, %eax
movslq (%r13,%rax,4), %rax
addq %r13, %rax
jmpq *%rax
testb $0x1, -0x2c(%rbp)
jne 0x70308
jmp 0x70339
xorl %ebx, %ebx
movl -0x38(%rbp), %r14d
movl -0x34(%rbp), %r15d
jmp 0x70351
testb $0x4, -0x2c(%rbp)
je 0x70339
movl $0x1010001, %r15d       # imm = 0x1010001
movb $0x8, %r14b
movb $0x4, %bl
jmp 0x70351
testb $0x8, -0x2c(%rbp)
je 0x70339
movl $0x1010001, %r15d       # imm = 0x1010001
movb $0x10, %r14b
jmp 0x7034f
cmpw $0x0, -0x2c(%rbp)
jns 0x70339
movl $0x1010001, %r15d       # imm = 0x1010001
movb $0x3, %r14b
movb $0x1, %bl
jmp 0x70351
xorl %ebx, %ebx
movl -0x40(%rbp), %r14d
movl -0x3c(%rbp), %r15d
jmp 0x70351
testb $0x2, -0x2c(%rbp)
jne 0x70346
xorl %ebx, %ebx
xorl %r14d, %r14d
movl $0x1010000, %r15d       # imm = 0x1010000
jmp 0x70351
movl $0x1010001, %r15d       # imm = 0x1010001
movb $0xe, %r14b
movb $0x8, %bl
movzbl %r12b, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
movzbl %r14b, %edi
callq 0x591af
xorl %edi, %edi
callq 0x591af
movl %r15d, %edi
callq 0x593b5
incl %r12d
cmpl $0x7, %r12d
jne 0x702c8
callq 0x5f4ce
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xaff7
cmpl $0x0, -0x30(%rbp)
leaq 0x18(%rsp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
je 0x70236
movl $0x6, %edi
jmp 0x6a306