// File: 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
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
leaq 0x2fceb5(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x9934f
jmp 0x99585
movl $0x63e, %edi            # imm = 0x63E
movl $0x3c, %esi
callq 0x83710
xorl %edi, %edi
callq 0x7b210
movl $0x20, %edi
callq 0x7b210
movl $0xff, %edi
callq 0x7b210
movl $0x7, %edi
callq 0x7b210
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x7, -0xc(%rbp)
jge 0x99561
movl $0x1010000, -0x20(%rbp) # imm = 0x1010000
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x993e4
movl -0x4(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x993df
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x8, -0x10(%rbp)
movl $0x10, -0x14(%rbp)
jmp 0x99511
cmpl $0x1, -0xc(%rbp)
jne 0x99413
movl -0x4(%rbp), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x9940e
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x1, -0x10(%rbp)
movl $0x3, -0x14(%rbp)
jmp 0x9950f
cmpl $0x2, -0xc(%rbp)
jne 0x99440
movl -0x4(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x9943b
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x4, -0x10(%rbp)
movl $0x8, -0x14(%rbp)
jmp 0x9950d
cmpl $0x3, -0xc(%rbp)
jne 0x9946d
movl -0x4(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x99468
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x8, -0x10(%rbp)
movl $0x10, -0x14(%rbp)
jmp 0x9950b
cmpl $0x4, -0xc(%rbp)
jne 0x994a4
movl -0x4(%rbp), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
je 0x994a2
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
orl $0x2000000, %eax        # imm = 0x2000000
movl %eax, -0x20(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x8, -0x14(%rbp)
jmp 0x99509
cmpl $0x5, -0xc(%rbp)
jne 0x994db
movl -0x4(%rbp), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x994d9
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
orl $0x4000000, %eax        # imm = 0x4000000
movl %eax, -0x20(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x3, -0x14(%rbp)
jmp 0x99507
cmpl $0x6, -0xc(%rbp)
jne 0x99505
movl -0x4(%rbp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x99503
movl -0x20(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x8, -0x10(%rbp)
movl $0xe, -0x14(%rbp)
jmp 0x99505
jmp 0x99507
jmp 0x99509
jmp 0x9950b
jmp 0x9950d
jmp 0x9950f
jmp 0x99511
movl -0x10(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0xc(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl -0x10(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
movl -0x14(%rbp), %eax
movzbl %al, %edi
callq 0x7b210
xorl %edi, %edi
callq 0x7b210
movl -0x20(%rbp), %edi
callq 0x7b520
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x99398
callq 0x83820
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xb8b0
cmpl $0x0, -0x8(%rbp)
je 0x99585
movl $0x6, %edi
movl $0x1c, %esi
callq 0x90d70
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)