// File: /workspace/github_cpp_makefile_star2_O2/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 0x2bf9a1(%rip), %rax    # 0x32101a
cmpb $0x0, (%rax)
jne 0x617f6
leaq 0x1c78b5(%rip), %rax    # 0x228f3e
cmpb $0x0, (%rax)
jne 0x617f6
leaq 0x1a3b9d(%rip), %rax    # 0x205236
cmpb $0x0, (%rax)
jne 0x617f6
movl %edi, %ebx
leaq 0x1a1225(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x617cb
cmpq $0x4, %rax
je 0x6178a
cmpq $0x8000, %rax           # imm = 0x8000
je 0x617ba
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
je 0x617a4
cmpq $0x200000, %rax         # imm = 0x200000
je 0x61729
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x6176e
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
je 0x6173a
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x617f6
pushq $0x1
popq %rbx
movl %ebx, %edi
callq 0x5be9f
leaq 0xa9b09(%rip), %rdi     # 0x10b221
movl %ebx, %esi
callq 0x576d4
callq 0x5be85
jmp 0x61893
leaq 0xa9b2a(%rip), %rdi     # 0x10b25a
callq 0x57acc
jmp 0x61893
cmpb $0x6, %bl
je 0x61821
movzbl %bl, %eax
cmpl $0xff, %eax
je 0x61819
cmpl $0x81, %eax
je 0x6181d
cmpl $0x80, %eax
jne 0x617f6
pushq $0x2
jmp 0x61823
callq 0x63a25
callq 0x63a49
testl %eax, %eax
je 0x61893
callq 0x63aee
jmp 0x61893
cmpb $-0x1, %bl
je 0x61806
movzbl %bl, %eax
cmpl $0x6, %eax
je 0x617fd
cmpl $0x3, %eax
jne 0x61893
pushq $0x8
jmp 0x617ff
leaq 0xa9a9b(%rip), %rdi     # 0x10b246
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x576d4
jmp 0x61893
leaq 0xa9a8a(%rip), %rdi     # 0x10b24b
callq 0x5c473
jmp 0x61893
leaq 0x1a3802(%rip), %rax    # 0x204fd4
movl (%rax), %eax
cmpl $0x33, %eax
je 0x617f6
cmpl $0x36, %eax
je 0x617f6
cmpl $0x50, %eax
je 0x617f6
cmpl $0x41, %eax
jne 0x61846
leaq 0x1a1115(%rip), %rax    # 0x202904
cmpb $0x0, (%rax)
jne 0x61852
jmp 0x61864
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
pushq $0x10
popq %rdx
xorl %edi, %edi
movl %edx, %esi
jmp 0x61812
xorl %edi, %edi
movl $0x41f, %esi            # imm = 0x41F
movl $0x41f, %edx            # imm = 0x41F
callq 0x59dc8
jmp 0x61893
pushq $0x7
jmp 0x61823
pushq $0x1
jmp 0x61823
pushq $0x4
popq %rdx
leaq 0x2c49f5(%rip), %rbx    # 0x326220
leaq 0xa99f9(%rip), %rsi     # 0x10b22b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x57791
jmp 0x61893
leaq 0x1a10b7(%rip), %rax    # 0x202904
cmpb $0x0, (%rax)
je 0x6186b
cmpb $0x7, %bl
jne 0x61864
pushq $0x1
popq %rdi
pushq $0x3
popq %rsi
callq 0x6355d
jmp 0x6188a
callq 0x5988e
jmp 0x6188a
movl $0x8e, %edi
callq 0x5707f
pushq $0x4c
popq %rdi
callq 0x523f2
movzbl %bl, %edi
callq 0x523f2
callq 0x570f8
leaq 0x1a39a7(%rip), %rax    # 0x205238
incl (%rax)
movl $0x1f6, %edi            # imm = 0x1F6
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x9d23