// File: /workspace/github_cpp_makefile_star2_O1/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 0x2ccd07(%rip), %rax    # 0x33701a
cmpb $0x0, (%rax)
jne 0x6a5f6
leaq 0x1d4c1b(%rip), %rax    # 0x23ef3e
cmpb $0x0, (%rax)
jne 0x6a5f6
leaq 0x1b0f03(%rip), %rax    # 0x21b236
cmpb $0x0, (%rax)
jne 0x6a5f6
movl %edi, %ebx
leaq 0x1ae58b(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1fffff, %rax         # imm = 0x1FFFFF
jg 0x6a39f
cmpq $0x7fff, %rax           # imm = 0x7FFF
jg 0x6a3ef
cmpq $0x1, %rax
je 0x6a475
cmpq $0x4, %rax
jne 0x6a5f6
cmpb $-0x1, %bl
je 0x6a57b
movzbl %bl, %eax
cmpl $0x6, %eax
je 0x6a56d
cmpl $0x3, %eax
jne 0x6a627
xorl %edi, %edi
movl $0x8, %esi
movl $0x8, %edx
jmp 0x6a587
cmpq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
jg 0x6a43e
cmpq $0x200000, %rax         # imm = 0x200000
je 0x6a4e8
cmpq $0x2000000, %rax        # imm = 0x2000000
jne 0x6a5f6
leaq 0xb9a92(%rip), %rdi     # 0x123e5c
movl $0x2c8, %esi            # imm = 0x2C8
callq 0x5ee52
callq 0x6cc14
testl %eax, %eax
je 0x6a627
leaq 0xb9a8f(%rip), %rdi     # 0x123e77
movl $0x2cd, %esi            # imm = 0x2CD
jmp 0x6a46b
cmpq $0x8000, %rax           # imm = 0x8000
je 0x6a4f9
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x6a5f6
movl $0x1, %edi
callq 0x63db5
leaq 0xb6de1(%rip), %rdi     # 0x1211f9
movl $0x1, %esi
callq 0x5ee52
leaq 0x1b05c3(%rip), %rax    # 0x21a9ec
cmpl $0x0, (%rax)
jne 0x6a627
xorl %edi, %edi
callq 0x63db5
jmp 0x6a627
movl $0x80000000, %ecx       # imm = 0x80000000
cmpq %rcx, %rax
je 0x6a514
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
cmpq %rcx, %rax
jne 0x6a5f6
leaq 0xb6db8(%rip), %rdi     # 0x12121e
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x5ee52
jmp 0x6a627
leaq 0x1b0b58(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
movl %ecx, %esi
xorl $0x41, %esi
leaq 0x1ae46e(%rip), %rdx    # 0x2188f8
movl (%rdx), %edx
movl %edx, %edi
xorl $0x47, %edi
orl %esi, %edi
je 0x6a4bb
cmpl $0x41, %ecx
jne 0x6a4a4
cmpl $0x33, %edx
je 0x6a4bb
cmpl $0x47, %edx
je 0x6a4bb
cmpl $0x41, %ecx
sete %dl
cmpq $0x1, %rax
sete %sil
testb %dl, %sil
je 0x6a5bf
leaq 0x1ae442(%rip), %rdx    # 0x218904
cmpb $0x0, (%rdx)
je 0x6a54e
cmpb $0x7, %bl
jne 0x6a563
movl $0x1, %edi
movl $0x3, %esi
callq 0x6c67b
jmp 0x6a61e
leaq 0xb6d43(%rip), %rdi     # 0x121232
callq 0x5f2a0
jmp 0x6a627
leaq 0xb6d23(%rip), %rdi     # 0x121223
callq 0xa36fd
movl $0x1, %edi
callq 0xa3789
jmp 0x6a627
movzbl %bl, %eax
cmpl $0x80, %eax
jg 0x6a535
cmpl $0x6, %eax
je 0x6a591
cmpl $0x80, %eax
jne 0x6a5f6
movl $0x2, %edx
jmp 0x6a59d
cmpl $0x81, %eax
je 0x6a598
cmpl $0xff, %eax
jne 0x6a5f6
movl $0x7, %edx
jmp 0x6a59d
cmpl $0x41, %ecx
setne %cl
cmpq $0x1, %rax
setne %al
orb %cl, %al
jne 0x6a5fd
callq 0x614be
jmp 0x6a61e
xorl %edi, %edi
movl $0x10, %esi
movl $0x10, %edx
jmp 0x6a587
xorl %edi, %edi
movl $0x41f, %esi            # imm = 0x41F
movl $0x41f, %edx            # imm = 0x41F
callq 0x61a3f
jmp 0x6a627
movl $0x4, %edx
jmp 0x6a59d
movl $0x1, %edx
leaq 0x2d1c7c(%rip), %rbx    # 0x33c220
leaq 0xb6c58(%rip), %rsi     # 0x121203
movq %rbx, %rdi
xorl %eax, %eax
callq 0x9060
movq %rbx, %rdi
callq 0x5ef13
jmp 0x6a627
cmpq $0x1, %rax
sete %dl
cmpl $0x50, %ecx
sete %sil
testb %sil, %dl
jne 0x6a5f6
cmpq $0x1, %rax
jne 0x6a4bb
leal -0x33(%rcx), %edx
cmpl $0x1d, %edx
ja 0x6a4bb
movl $0x20004009, %esi       # imm = 0x20004009
btl %edx, %esi
jae 0x6a4bb
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
movl $0x8e, %edi
callq 0x5e740
movl $0x4c, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
callq 0x5e7c0
leaq 0x1b0c13(%rip), %rax    # 0x21b238
incl (%rax)
movl $0x1f6, %edi            # imm = 0x1F6
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x9d80