// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: set_discipline_mode(unsigned char)
void set_discipline_mode(u08 mode)
{
   if(read_only) return;
   if(luxor) return;

   // mode 0: jam sync
   // mode 1: enter recovery
   // mode 2: manual holdover
   // mode 3: exit manual holdover
   // mode 4: disable disciplining
   // mode 5: enable disciplining

   if(rcvr_type == CS_RCVR) {
      set_cs_remote(1);
      if     (mode == SET_DIS_MODE_DISABLE) queue_cs_cmd(":PTIM:STAN 0", CS_STANDBY_MSG);
      else if(mode == SET_DIS_MODE_ENABLE)  queue_cs_cmd(":PTIM:STAN 1", CS_STANDBY_MSG);
      restore_cs_remote();
      queue_cs_cmd(":PTIM:STAN?", CS_STANDBY_MSG);
   }
   else if(rcvr_type == PRS_RCVR) {
      // !!!!! LO command does not respond with "OK" in verbose mode... use -PRS_LO_MSG kludge
      if     (mode == SET_DIS_MODE_HOLDOVER) queue_prs_cmd("LO0", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_DISABLE)  queue_prs_cmd("LO0", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_NORMAL)   queue_prs_cmd("LO1", -PRS_LO_MSG);
      else if(mode == SET_DIS_MODE_ENABLE)   queue_prs_cmd("LO1", -PRS_LO_MSG);
      queue_prs_cmd("LO?", PRS_LO_MSG);
      queue_prs_cmd("ST?", PRS_ST_MSG);
   }
   else if(rcvr_type == SRO_RCVR) {
      if(mode == SET_DIS_MODE_JAMSYNC) {      // sync now
         set_sro_sy(1);
      }
      else if(mode == SET_DIS_MODE_DISABLE) { // free run
         set_sro_tr(0);
      }
      else if(mode == SET_DIS_MODE_ENABLE) {  // track now+always
         set_sro_tr(3);
      }
   }
   else if(rcvr_type == STAR_RCVR) {
      if(star_type == OSA_TYPE) {
         if     (mode == SET_DIS_MODE_HOLDOVER) queue_star_cmd("MODE=HOLDOVER", STAR_HOLD_MSG);
         else if(mode == SET_DIS_MODE_NORMAL)   queue_star_cmd("MODE=AUTOMATIC", STAR_HOLD_MSG);
      }
      else {
         if     (mode == SET_DIS_MODE_HOLDOVER) queue_star_cmd("MODE=H;", STAR_HOLD_MSG);
         else if(mode == SET_DIS_MODE_NORMAL)   queue_star_cmd("MODE=A;", STAR_HOLD_MSG);
      }
      request_rcvr_config(8855);
   }
   else if(rcvr_type == SCPI_RCVR) {  // 2=exit holdover  3=force holdover
      z_rcvr:
if(debug_file) fprintf(debug_file, "set_dmode(%d)\n", mode);
      extend_com_timeout(0.0);
      if(scpi_type == NORTEL_TYPE) {
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd("ROSC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd("ROSC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_JAMSYNC)  queue_scpi_cmd("SYNC:IMMEDIATE", SCPI_JAMSYNC_MSG);
         queue_scpi_cmd("ROSC:HOLD:DUR?", SCPI_HOLDOVER_MSG);
      }
      else {
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd(":SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd(":SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_JAMSYNC)  queue_scpi_cmd(":SYNC:IMM", SCPI_JAMSYNC_MSG);
         queue_scpi_cmd(":ROSC:HOLD:DUR?", SCPI_HOLDOVER_MSG);
      }
   }
   else if(rcvr_type == UCCM_RCVR) { 
      if(scpi_type == UCCMP_TYPE) goto z_rcvr;
      else if(scpi_type == SAMSUNG_TYPE) {  // samsung
         if     (mode == SET_DIS_MODE_NORMAL)   queue_scpi_cmd("SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_HOLDOVER) queue_scpi_cmd("SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_DISABLE)  queue_scpi_cmd("SYNC:HOLD:INIT", SCPI_HOLDOVER_MSG);
         else if(mode == SET_DIS_MODE_ENABLE)   queue_scpi_cmd("SYNC:HOLD:REC:INIT", SCPI_HOLDOVER_MSG);
      }
      else if((mode == SET_DIS_MODE_HOLDOVER) || (mode == SET_DIS_MODE_DISABLE)) {  // disable disciplining at current EFC
         set_dac_voltage(uccm_voltage, 20);
      }
      else if((mode == SET_DIS_MODE_RECOVER) || (mode == SET_DIS_MODE_NORMAL) || (mode == SET_DIS_MODE_ENABLE)) {  // enable disciplining
         queue_uccm_cmd("DIAG:ROSC:EFC:DATA GPS", UCCM_SETDAC_MSG);
         queue_uccm_cmd("DIAG:ROSC:EFC:DATA?", UCCM_EFC_MSG);
         discipline_mode = DIS_MODE_RECOVERY;  // recovery
      }
   }
   else if(rcvr_type == TSIP_RCVR) {
      if(ACU_GG) return;
      if(ACU_360) return;
      if(ACUTIME) return;
      if(PALISADE) return;
      if(SV6_FAMILY) return;
      send_tsip_start(0x8E);
      send_byte(0xA3);
      send_byte(mode);
      send_tsip_end();
   }
   else if(rcvr_type == X72_RCVR) {
      if     (mode == SET_DIS_MODE_HOLDOVER) set_x72_discipline(0);
      else if(mode == SET_DIS_MODE_DISABLE)  set_x72_discipline(0);
      else if(mode == SET_DIS_MODE_NORMAL)   set_x72_discipline(1);
      else if(mode == SET_DIS_MODE_ENABLE)   set_x72_discipline(1);
      else if(mode == SET_DIS_MODE_JAMSYNC) {
         update_x72_tic(x72_pps, 4);
      }
   }

   if(mode == SET_DIS_MODE_JAMSYNC) {
      osc_integral = 0.0;
      have_osc = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x2c993f(%rip), %rax    # 0x33701a
leaq 0x1d185c(%rip), %rcx    # 0x23ef3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x6db1f
movl %edi, %ebx
leaq 0x1ab1db(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x1ffff, %rax          # imm = 0x1FFFF
jg 0x6d761
cmpq $0xf, %rax
jg 0x6d7c9
cmpq $0x1, %rax
je 0x6d8b5
cmpq $0x8, %rax
jne 0x6db00
leaq 0x1ad8bb(%rip), %rax    # 0x21afe0
movl (%rax), %eax
cmpl $0x50, %eax
je 0x6d854
cmpl $0x53, %eax
jne 0x6da27
cmpb $0x5, %bl
ja 0x6db1f
movzbl %bl, %eax
leaq 0xb1380(%rip), %rcx     # 0x11eacc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb34b3(%rip), %rdi     # 0x120c0f
jmp 0x6dad0
cmpq $0x1ffffff, %rax        # imm = 0x1FFFFFF
jg 0x6d810
cmpq $0x20000, %rax          # imm = 0x20000
je 0x6d94e
cmpq $0x1000000, %rax        # imm = 0x1000000
jne 0x6db00
leal -0x2(%rbx), %eax
cmpb $0x3, %al
ja 0x6d7a7
movzbl %al, %eax
leaq 0xb279e(%rip), %rcx     # 0x11ff34
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x5ee52
leaq 0xb3be3(%rip), %rdi     # 0x121391
movl $0x1fb, %esi            # imm = 0x1FB
callq 0x5ee52
leaq 0xb80d9(%rip), %rdi     # 0x125898
movl $0x1f9, %esi            # imm = 0x1F9
jmp 0x6dad5
cmpq $0x10, %rax
je 0x6d854
cmpq $0x1000, %rax           # imm = 0x1000
jne 0x6db00
leaq 0x1ad802(%rip), %rax    # 0x21afe8
cmpl $0x4f, (%rax)
jne 0x6d9c2
cmpb $0x2, %bl
je 0x6dadc
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x6daf6
leaq 0xb3b98(%rip), %rdi     # 0x1213a3
jmp 0x6daec
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x6d976
cmpq $0x8000000, %rax        # imm = 0x8000000
jne 0x6db00
cmpb $0x5, %bl
je 0x6da76
movzbl %bl, %eax
cmpl $0x4, %eax
je 0x6da72
testl %eax, %eax
jne 0x6db1f
movl $0x1, %edi
callq 0x6db73
jmp 0x6db00
leaq 0x1d0b35(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6d874
movzbl %bl, %edx
leaq 0xb3b55(%rip), %rsi     # 0x1213c2
xorl %eax, %eax
callq 0x9560
xorps %xmm0, %xmm0
callq 0x63c5c
leaq 0x1ad75d(%rip), %rax    # 0x21afe0
cmpl $0x4e, (%rax)
jne 0x6d999
testb %bl, %bl
je 0x6da9e
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x6da82
cmpl $0x3, %eax
jne 0x6daaf
leaq 0xb3b21(%rip), %rdi     # 0x1213d1
jmp 0x6da89
leaq 0x1ad718(%rip), %rcx    # 0x21afd4
movl (%rcx), %ecx
movl %ecx, %esi
xorl $0x41, %esi
leaq 0x1ab02e(%rip), %rdx    # 0x2188f8
movl (%rdx), %edx
movl %edx, %edi
xorl $0x47, %edi
orl %esi, %edi
je 0x6db1f
cmpl $0x41, %ecx
jne 0x6d8f0
cmpl $0x33, %edx
je 0x6db1f
cmpl $0x47, %edx
je 0x6db1f
cmpl $0x41, %ecx
sete %dl
cmpl $0x50, %ecx
sete %sil
cmpq $0x1, %rax
jne 0x6d90c
orb %sil, %dl
jne 0x6db1f
cmpq $0x1, %rax
jne 0x6d928
addl $-0x33, %ecx
cmpl $0x1d, %ecx
ja 0x6d928
movl $0x20004009, %eax       # imm = 0x20004009
btl %ecx, %eax
jb 0x6db1f
movl $0x8e, %edi
callq 0x5e740
movl $0xa3, %edi
callq 0x591af
movzbl %bl, %edi
callq 0x591af
callq 0x5e7c0
jmp 0x6db00
movl $0x1, %edi
callq 0x63db5
cmpb $0x4, %bl
je 0x6d9e3
movzbl %bl, %eax
cmpl $0x5, %eax
jne 0x6d9f4
leaq 0xb2ea4(%rip), %rdi     # 0x120818
jmp 0x6d9ea
cmpb $0x5, %bl
ja 0x6db1f
movzbl %bl, %eax
leaq 0xb112b(%rip), %rcx     # 0x11eab4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
jmp 0x6da1d
testb %bl, %bl
je 0x6dab8
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x6da90
cmpl $0x3, %eax
jne 0x6dac9
leaq 0xb3251(%rip), %rdi     # 0x120c0e
jmp 0x6da97
cmpb $0x2, %bl
je 0x6dae5
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x6daf6
leaq 0xb39dc(%rip), %rdi     # 0x1213ba
jmp 0x6daec
leaq 0xb3986(%rip), %rdi     # 0x121370
movl $0x143, %esi            # imm = 0x143
callq 0x5ee52
leaq 0x1acff1(%rip), %rax    # 0x21a9ec
cmpl $0x0, (%rax)
jne 0x6da07
xorl %edi, %edi
callq 0x63db5
leaq 0xb396f(%rip), %rdi     # 0x12137d
movl $0x143, %esi            # imm = 0x143
jmp 0x6dad5
movl $0x1, %edi
callq 0x6dc2d
jmp 0x6db00
cmpb $0x5, %bl
ja 0x6db1f
movzbl %bl, %eax
movl $0x2a, %ecx
btl %eax, %ecx
jae 0x6db46
leaq 0xb39d5(%rip), %rdi     # 0x12141d
movl $0x68, %esi
callq 0x5ee52
leaq 0xb3843(%rip), %rdi     # 0x12129c
movl $0x67, %esi
callq 0x5ee52
leaq 0x29fa2d(%rip), %rax    # 0x30d497
movb $0x4, (%rax)
jmp 0x6db00
xorl %edi, %edi
jmp 0x6da7b
movl $0x3, %edi
callq 0x6dbd0
jmp 0x6db00
leaq 0xb395b(%rip), %rdi     # 0x1213e4
movl $0x16, %esi
jmp 0x6daaa
leaq 0xb395c(%rip), %rdi     # 0x1213f3
movl $0x16, %esi
jmp 0x6dac4
leaq 0xb30ed(%rip), %rdi     # 0x120b92
movl $0x21, %esi
callq 0x5ee52
leaq 0xb3958(%rip), %rdi     # 0x12140e
jmp 0x6dad0
leaq 0xb3944(%rip), %rdi     # 0x121403
movl $0x21, %esi
callq 0x5ee52
leaq 0xb393d(%rip), %rdi     # 0x12140d
movl $0x16, %esi
callq 0x5ee52
jmp 0x6db00
leaq 0xb38b2(%rip), %rdi     # 0x121395
jmp 0x6daec
leaq 0xb38c6(%rip), %rdi     # 0x1213b2
movl $0xfc, %esi
callq 0x5ee52
movl $0x2297, %edi           # imm = 0x2297
callq 0x66617
testb %bl, %bl
jne 0x6db1f
leaq 0x1ad705(%rip), %rax    # 0x21b210
movq $0x0, (%rax)
leaq 0x1d13cb(%rip), %rax    # 0x23eee4
movl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x1ad2cf(%rip), %rax    # 0x21adfc
movl (%rax), %edi
incl 0x30c20b(%rip)          # 0x379d40
callq 0x8fb74
movl $0x0, 0x308b18(%rip)    # 0x37665c
jmp 0x6db00
movl $0x14, %ecx
btl %eax, %ecx
jae 0x6db04
leaq 0x29eeb1(%rip), %rax    # 0x30ca08
movsd (%rax), %xmm0
movl $0x14, %edi
callq 0x6ced6
jmp 0x6db00
leaq 0xb3886(%rip), %rdi     # 0x1213f4
jmp 0x6dad0