// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: save_segment(unsigned char, int)
void save_segment(u08 segment, int why)
{
int val;

   // save config info into EEPROM
   //     3 = receiver config
   //     6 = timing config  (ESIP_RCVR TIMEALIGN setting)
   //     7 = survey config
   //     9 = discipline config
   //   128 = ESIP_RCVR DEFLS default leap second info
   //   129 = ESIP_RCVR default FREQ command info
   //   255 = all info

   if(read_only) return;
   if(luxor) return;
   if(no_eeprom_writes) return;

   if(rcvr_type == CS_RCVR) {
      set_cs_remote(1);
      queue_cs_cmd("SYST:SCON", SCPI_NULL_MSG);
      restore_cs_remote();
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == ESIP_RCVR) {
      val = 0;
      if     (segment == 6)   val |= 0x04;  // TIMEALIGN timing info
      else if(segment == 128) val |= 0x02;  // DEFLS default leap second
      else if(segment == 129) val |= 0x01;  // FREQ command info
      else if(segment == 255) val |= 0x07;  // all info
      else return;

      sprintf(out, "PERDAPI,FLASHBACKUP,0x%02X", val);
      send_esip_cmd(out);  // update flash memory settings
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == SA35_RCVR) {
      queue_sa35_cmd("<FS>", SA35_SAVE_CMD);
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == TAIP_RCVR) {
      send_taip_cmd("SRTSAVE_CONFIG");  // update flash memory settings
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == TRUE_RCVR) {
      send_true_cmd("$UPDATE FLASH");  // update flash memory settings
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(ACU_GG) ;
      else if(ACU_360) ;
      else if(ACUTIME);
      else if(PALISADE) return;
      else if(SV6_FAMILY) return;
      if(res_t) {
         if(segment == 7) start_self_survey(1, 3);  // save survey params
         else             write_all_nvs();          // save current config
      }
      else if(ACUTIME) {
         write_all_nvs();  // save current config
      }
      else {
         send_tsip_start(0x8E);
         send_byte(0x4C);
         send_byte(segment);
         send_tsip_end();
      }
      ++ee_write_count;
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == UBX_RCVR) {
      if     (segment == 3)   update_ubx_config(0x0000, UBX_EE_NAV, UBX_EE_NAV);
      else if(segment == 6)   update_ubx_config(0x0000, UBX_EE_TP, UBX_EE_TP);
      else if(segment == 255) update_ubx_config(0x0000, UBX_EE_ALL, UBX_EE_ALL);
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }
   else if(rcvr_type == X72_RCVR) {
      save_x72_tune();
      if(x72_fw_discipline()) {
         save_x72_dmode();
      }
      BEEP(502);   // !!! if you hear lots of beeps,  you may be wearing out the EEPROM
   }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2ccb3f(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
jne 0x6a6db
leaq 0x1d4a53(%rip), %rax    # 0x23ef3e
cmpb $0x0, (%rax)
jne 0x6a6db
leaq 0x1b0d3b(%rip), %rax    # 0x21b236
cmpb $0x0, (%rax)
jne 0x6a6db
movl %edi, %ebx
leaq 0x1ae3c3(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jg 0x6a567
cmpq $0x7fff, %rax           # imm = 0x7FFF
jg 0x6a5b7
cmpq $0x1, %rax
je 0x6a639
cmpq $0x4, %rax
jne 0x6a6db
cmpb $-0x1, %bl
je 0x6a6f0
movzbl %bl, %eax
cmpl $0x6, %eax
je 0x6a6e2
cmpl $0x3, %eax
jne 0x6a787
xorl %edi, %edi
movl $0x8, %esi
movl $0x8, %edx
jmp 0x6a6fc
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jg 0x6a606
cmpq $0x200000, %rax         # imm = 0x200000
je 0x6a65e
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x6a6db
leaq 0xb99aa(%rip), %rdi     # 0x123f3c
movl $0x2c8, %esi            # imm = 0x2C8
callq 0x5edda
callq 0x6cbe4
testl %eax, %eax
je 0x6a787
leaq 0xb99a7(%rip), %rdi     # 0x123f57
movl $0x2cd, %esi            # imm = 0x2CD
jmp 0x6a62f
cmpq $0x8000, %rax           # imm = 0x8000
je 0x6a66f
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x6a6db
movl $0x1, %edi
callq 0x63e3b
leaq 0xb6cf9(%rip), %rdi     # 0x1212d9
movl $0x1, %esi
callq 0x5edda
leaq 0x1b03fb(%rip), %rax    # 0x21a9ec
cmpl $0x0, (%rax)
jne 0x6a787
xorl %edi, %edi
callq 0x63e3b
jmp 0x6a787
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
je 0x6a68a
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
jne 0x6a6db
leaq 0xb6cd4(%rip), %rdi     # 0x1212fe
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x5edda
jmp 0x6a787
leaq 0x1b0994(%rip), %rax    # 0x21afd4
movl (%rax), %eax
cmpl $0x40, %eax
jg 0x6a6ae
cmpl $0x33, %eax
je 0x6a6db
cmpl $0x36, %eax
je 0x6a6db
jmp 0x6a706
leaq 0xb6cad(%rip), %rdi     # 0x121312
callq 0x5f228
jmp 0x6a787
leaq 0xb6c8d(%rip), %rdi     # 0x121303
callq 0xa3914
movl $0x1, %edi
callq 0xa39a0
jmp 0x6a787
movzbl %bl, %eax
cmpl $0x80, %eax
jg 0x6a6c6
cmpl $0x6, %eax
je 0x6a72f
cmpl $0x80, %eax
jne 0x6a6db
movl $0x2, %edx
jmp 0x6a73b
cmpl $0x50, %eax
je 0x6a6db
cmpl $0x41, %eax
jne 0x6a706
leaq 0x1ae245(%rip), %rax    # 0x218904
cmpb $0x0, (%rax)
jne 0x6a712
jmp 0x6a728
cmpl $0x81, %eax
je 0x6a736
cmpl $0xff, %eax
jne 0x6a6db
movl $0x7, %edx
jmp 0x6a73b
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
xorl %edi, %edi
movl $0x10, %esi
movl $0x10, %edx
jmp 0x6a6fc
xorl %edi, %edi
movl $0x41f, %esi            # imm = 0x41F
movl $0x41f, %edx            # imm = 0x41F
callq 0x619b5
jmp 0x6a787
leaq 0x1ae1f7(%rip), %rax    # 0x218904
cmpb $0x0, (%rax)
je 0x6a75d
cmpb $0x7, %bl
jne 0x6a728
movl $0x1, %edi
movl $0x3, %esi
callq 0x6c6a4
jmp 0x6a77e
callq 0x6146a
jmp 0x6a77e
movl $0x4, %edx
jmp 0x6a73b
movl $0x1, %edx
leaq 0x2d1ade(%rip), %rbx    # 0x33c220
leaq 0xb6b9a(%rip), %rsi     # 0x1212e3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x5ee9b
jmp 0x6a787
movl $0x8e, %edi
callq 0x5e6be
movl $0x4c, %edi
callq 0x590f7
movzbl %bl, %edi
callq 0x590f7
callq 0x5e73c
leaq 0x1b0ab3(%rip), %rax    # 0x21b238
incl (%rax)
movl $0x1f6, %edi            # imm = 0x1F6
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x9d78