// File: /workspace/github_cpp_makefile_star2_O2/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 0x2bccc1(%rip), %rax    # 0x32101a
leaq 0x1c4bde(%rip), %rcx    # 0x228f3e
movb (%rcx), %cl
orb (%rax), %cl
jne 0x64709
movl %edi, %ebx
leaq 0x19e55d(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x1, %rax
je 0x64553
cmpq $0x8, %rax
je 0x64482
cmpq $0x10, %rax
je 0x644c1
cmpq $0x1000, %rax           # imm = 0x1000
je 0x64522
cmpq $0x8000000, %rax        # imm = 0x8000000
je 0x643f1
cmpq $0x1000000, %rax        # imm = 0x1000000
je 0x6443e
cmpq $0x2000000, %rax        # imm = 0x2000000
je 0x6441b
cmpq $0x20000, %rax          # imm = 0x20000
jne 0x646f0
pushq $0x1
popq %rdi
callq 0x5be9f
cmpb $0x4, %bl
je 0x645f0
movzbl %bl, %eax
cmpl $0x5, %eax
jne 0x64601
leaq 0xa6454(%rip), %rdi     # 0x10a840
jmp 0x645f7
cmpb $0x5, %bl
je 0x64660
movzbl %bl, %eax
cmpl $0x4, %eax
je 0x6465c
testl %eax, %eax
jne 0x64709
pushq $0x1
popq %rdi
callq 0x64746
jmp 0x646f4
cmpb $0x5, %bl
ja 0x64709
movzbl %bl, %eax
leaq 0xa4686(%rip), %rcx     # 0x108ab4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %edi, %edi
jmp 0x645e5
leal -0x2(%rbx), %eax
cmpb $0x3, %al
ja 0x64460
movzbl %al, %eax
leaq 0xa5b01(%rip), %rcx     # 0x109f50
movslq (%rcx,%rax,4), %rdi
addq %rcx, %rdi
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x576d4
leaq 0xa6f52(%rip), %rdi     # 0x10b3b9
movl $0x1fb, %esi            # imm = 0x1FB
callq 0x576d4
leaq 0xab448(%rip), %rdi     # 0x10f8c0
movl $0x1f9, %esi            # imm = 0x1F9
jmp 0x646eb
leaq 0x1a0b57(%rip), %rax    # 0x204fe0
movl (%rax), %eax
cmpl $0x50, %eax
je 0x644c1
cmpl $0x53, %eax
jne 0x64617
cmpb $0x5, %bl
ja 0x64709
movzbl %bl, %eax
leaq 0xa4620(%rip), %rcx     # 0x108acc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa677b(%rip), %rdi     # 0x10ac37
jmp 0x64738
leaq 0x1c3ec8(%rip), %rax    # 0x228390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x644e1
movzbl %bl, %edx
leaq 0xa6f10(%rip), %rsi     # 0x10b3ea
xorl %eax, %eax
callq 0x9560
xorps %xmm0, %xmm0
callq 0x5bd83
leaq 0x1a0af0(%rip), %rax    # 0x204fe0
cmpl $0x4e, (%rax)
jne 0x64598
testb %bl, %bl
je 0x646ba
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x6467e
cmpl $0x3, %eax
jne 0x646c9
leaq 0xa6edc(%rip), %rdi     # 0x10b3f9
jmp 0x64685
leaq 0x1a0abf(%rip), %rax    # 0x204fe8
cmpl $0x4f, (%rax)
jne 0x645c1
cmpb $0x2, %bl
je 0x64694
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x646ae
leaq 0xa6e7d(%rip), %rdi     # 0x10b3cb
jmp 0x646a4
leaq 0x1a0a7a(%rip), %rax    # 0x204fd4
movl (%rax), %eax
addl $-0x33, %eax
cmpl $0x1d, %eax
ja 0x64572
movl $0x20004009, %ecx       # imm = 0x20004009
btl %eax, %ecx
jb 0x64709
movl $0x8e, %edi
callq 0x5707f
movl $0xa3, %edi
callq 0x523f2
movzbl %bl, %edi
callq 0x523f2
callq 0x570f8
jmp 0x646f0
testb %bl, %bl
je 0x646d2
movzbl %bl, %eax
cmpl $0x2, %eax
je 0x64689
cmpl $0x3, %eax
jne 0x646e1
leaq 0xa667a(%rip), %rdi     # 0x10ac36
jmp 0x64690
cmpb $0x2, %bl
je 0x6469d
movzbl %bl, %eax
cmpl $0x3, %eax
jne 0x646ae
leaq 0xa6e05(%rip), %rdi     # 0x10b3e2
jmp 0x646a4
pushq $0x1
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x647f2
leaq 0xa6da1(%rip), %rdi     # 0x10b398
movl $0x143, %esi            # imm = 0x143
callq 0x576d4
callq 0x5be85
leaq 0xa6d98(%rip), %rdi     # 0x10b3a5
movl $0x143, %esi            # imm = 0x143
jmp 0x646eb
cmpb $0x5, %bl
ja 0x64709
movzbl %bl, %eax
pushq $0x2a
popq %rcx
btl %eax, %ecx
jae 0x64710
leaq 0xa6e0f(%rip), %rdi     # 0x10b445
pushq $0x68
popq %rsi
callq 0x576d4
leaq 0xa6c7f(%rip), %rdi     # 0x10b2c4
pushq $0x67
popq %rsi
callq 0x576d4
leaq 0x292e43(%rip), %rax    # 0x2f7497
movb $0x4, (%rax)
jmp 0x64709
xorl %edi, %edi
jmp 0x64663
pushq $0x3
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x6479c
leaq 0x1a0787(%rip), %rax    # 0x204dfc
movl (%rax), %edi
callq 0x64928
jmp 0x646f4
leaq 0xa6d87(%rip), %rdi     # 0x10b40c
pushq $0x16
jmp 0x646c3
leaq 0xa6d8b(%rip), %rdi     # 0x10b41b
pushq $0x16
jmp 0x646db
leaq 0xa6d22(%rip), %rdi     # 0x10b3bd
jmp 0x646a4
leaq 0xa6d36(%rip), %rdi     # 0x10b3da
movl $0xfc, %esi
callq 0x576d4
movl $0x2297, %edi           # imm = 0x2297
callq 0x5e18e
jmp 0x646f0
leaq 0xa64f9(%rip), %rdi     # 0x10abba
pushq $0x21
popq %rsi
callq 0x576d4
leaq 0xa6d66(%rip), %rdi     # 0x10b436
jmp 0x646e8
leaq 0xa6d52(%rip), %rdi     # 0x10b42b
pushq $0x21
popq %rsi
callq 0x576d4
leaq 0xa6d4d(%rip), %rdi     # 0x10b435
pushq $0x16
popq %rsi
callq 0x576d4
testb %bl, %bl
jne 0x64709
leaq 0x1a0b15(%rip), %rax    # 0x205210
andq $0x0, (%rax)
leaq 0x1c47de(%rip), %rax    # 0x228ee4
andl $0x0, (%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
pushq $0x14
popq %rcx
btl %eax, %ecx
jae 0x646f4
leaq 0x2922e9(%rip), %rax    # 0x2f6a08
movsd (%rax), %xmm0
pushq $0x14
popq %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x63c97
leaq 0xa6ce4(%rip), %rdi     # 0x10b41c
pushq $0x16
popq %rsi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x576d4