// File: 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
subq $0x10, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movl %esi, -0x8(%rbp)
leaq 0x305472(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x90d92
jmp 0x9115c
leaq 0x20d385(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x90da3
jmp 0x9115c
leaq 0x1e966c(%rip), %rax    # 0x27a416
cmpb $0x0, (%rax)
je 0x90db4
jmp 0x9115c
leaq 0x1e6cf5(%rip), %rax    # 0x277ab0
cmpq $0x20000, (%rax)        # imm = 0x20000
jne 0x90df3
movl $0x1, %edi
callq 0x89280
leaq 0xf3794(%rip), %rdi     # 0x184569
movl $0x1, %esi
callq 0x82fd0
callq 0x89260
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x9115c
movl $0x80000000, %ecx       # imm = 0x80000000
leaq 0x1e6cb1(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x90ea3
movl $0x0, -0xc(%rbp)
movzbl -0x1(%rbp), %eax
cmpl $0x6, %eax
jne 0x90e23
movl -0xc(%rbp), %eax
orl $0x4, %eax
movl %eax, -0xc(%rbp)
jmp 0x90e70
movzbl -0x1(%rbp), %eax
cmpl $0x80, %eax
jne 0x90e39
movl -0xc(%rbp), %eax
orl $0x2, %eax
movl %eax, -0xc(%rbp)
jmp 0x90e6e
movzbl -0x1(%rbp), %eax
cmpl $0x81, %eax
jne 0x90e4f
movl -0xc(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x90e6c
movzbl -0x1(%rbp), %eax
cmpl $0xff, %eax
jne 0x90e65
movl -0xc(%rbp), %eax
orl $0x7, %eax
movl %eax, -0xc(%rbp)
jmp 0x90e6a
jmp 0x9115c
jmp 0x90e6c
jmp 0x90e6e
jmp 0x90e70
movl -0xc(%rbp), %edx
leaq 0x30a586(%rip), %rdi    # 0x39b400
leaq 0xf36f2(%rip), %rsi     # 0x184573
movb $0x0, %al
callq 0x9060
leaq 0x30a571(%rip), %rdi    # 0x39b400
callq 0x830d0
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x9115a
movabsq $0x1000000000, %rcx     # imm = 0x1000000000
leaq 0x1e6bfc(%rip), %rax    # 0x277ab0
cmpq %rcx, (%rax)
jne 0x90ed9
leaq 0xf36ce(%rip), %rdi     # 0x18458e
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x82fd0
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91158
leaq 0x1e6bd0(%rip), %rax    # 0x277ab0
cmpq $0x8000, (%rax)         # imm = 0x8000
jne 0x90f04
leaq 0xf36a3(%rip), %rdi     # 0x184593
callq 0x899c0
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91156
leaq 0x1e6ba5(%rip), %rax    # 0x277ab0
cmpq $0x200000, (%rax)       # imm = 0x200000
jne 0x90f2f
leaq 0xf3687(%rip), %rdi     # 0x1845a2
callq 0x83580
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91154
leaq 0x1e6b7a(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x910b8
leaq 0x1e6b69(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x90f6a
leaq 0x1e9260(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x90f6a
leaq 0x1e6b78(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x90f6a
jmp 0x91023
leaq 0x1e6b3f(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x90fa0
leaq 0x1e9236(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x90fa0
leaq 0x1e6b4e(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0x90f9b
leaq 0x1e6b42(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x90fa0
jmp 0x91021
leaq 0x1e6b09(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x90fbb
leaq 0x1e9200(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x90fbb
jmp 0x9101f
leaq 0x1e6aee(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x90fd9
leaq 0x1e91e5(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0x90fd9
jmp 0x9115c
leaq 0x1e6ad0(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9101b
leaq 0x1e91c7(%rip), %rax    # 0x27a1b4
cmpl $0x36, (%rax)
je 0x91016
leaq 0x1e91bb(%rip), %rax    # 0x27a1b4
cmpl $0x33, (%rax)
je 0x91016
leaq 0x1e91af(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
je 0x91016
leaq 0x1e91a3(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x9101b
jmp 0x9115c
jmp 0x9101d
jmp 0x9101f
jmp 0x91021
jmp 0x91023
leaq 0x1e6aba(%rip), %rax    # 0x277ae4
cmpb $0x0, (%rax)
je 0x91050
movzbl -0x1(%rbp), %eax
cmpl $0x7, %eax
jne 0x91049
movl $0x1, %edi
movl $0x3, %esi
callq 0x93b60
jmp 0x9104e
callq 0x85ef0
jmp 0x91094
leaq 0x1e6a59(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x91070
leaq 0x1e9150(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x91070
callq 0x85ef0
jmp 0x91092
movl $0x8e, %edi
callq 0x824f0
movl $0x4c, %edi
callq 0x7b210
movzbl -0x1(%rbp), %edi
callq 0x7b210
callq 0x82590
jmp 0x91094
leaq 0x1e937d(%rip), %rax    # 0x27a418
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1e9371(%rip), %rax    # 0x27a418
movl %ecx, (%rax)
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91152
leaq 0x1e69f1(%rip), %rax    # 0x277ab0
cmpq $0x4, (%rax)
jne 0x91120
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x910de
xorl %edi, %edi
movl $0x8, %edx
movl %edx, %esi
callq 0x86600
jmp 0x91114
movzbl -0x1(%rbp), %eax
cmpl $0x6, %eax
jne 0x910f7
xorl %edi, %edi
movl $0x10, %edx
movl %edx, %esi
callq 0x86600
jmp 0x91112
movzbl -0x1(%rbp), %eax
cmpl $0xff, %eax
jne 0x91110
xorl %edi, %edi
movl $0x41f, %edx            # imm = 0x41F
movl %edx, %esi
callq 0x86600
jmp 0x91112
jmp 0x91114
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91150
leaq 0x1e6989(%rip), %rax    # 0x277ab0
cmpq $0x2000000, (%rax)      # imm = 0x2000000
jne 0x9114e
callq 0x94200
callq 0x94230
cmpl $0x0, %eax
je 0x91144
callq 0x94360
movl $0x1f6, %edi            # imm = 0x1F6
callq 0x9ec0
jmp 0x91150
jmp 0x91152
jmp 0x91154
jmp 0x91156
jmp 0x91158
jmp 0x9115a
jmp 0x9115c
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)