// File: 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
subq $0x10, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
leaq 0x301065(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x9519f
jmp 0x957d2
leaq 0x208f78(%rip), %rax    # 0x29e11e
cmpb $0x0, (%rax)
je 0x951b0
jmp 0x957d2
leaq 0x1e28f9(%rip), %rax    # 0x277ab0
cmpq $0x20000, (%rax)        # imm = 0x20000
jne 0x9521d
movl $0x1, %edi
callq 0x89280
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x951e6
leaq 0xef506(%rip), %rdi     # 0x1846e0
movl $0x143, %esi            # imm = 0x143
callq 0x82fd0
jmp 0x95202
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x95200
leaq 0xee982(%rip), %rdi     # 0x183b78
movl $0x143, %esi            # imm = 0x143
callq 0x82fd0
jmp 0x95202
callq 0x89260
leaq 0xef4df(%rip), %rdi     # 0x1846ed
movl $0x143, %esi            # imm = 0x143
callq 0x82fd0
jmp 0x957ae
leaq 0x1e288c(%rip), %rax    # 0x277ab0
cmpq $0x1000000, (%rax)      # imm = 0x1000000
jne 0x952cc
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x9524d
leaq 0xef4b8(%rip), %rdi     # 0x1846f9
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x82fd0
jmp 0x952a5
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x95269
leaq 0xef49c(%rip), %rdi     # 0x1846f9
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x82fd0
jmp 0x952a3
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x95285
leaq 0xef484(%rip), %rdi     # 0x1846fd
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x82fd0
jmp 0x952a1
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x9529f
leaq 0xef468(%rip), %rdi     # 0x1846fd
movl $0xfffffe05, %esi       # imm = 0xFFFFFE05
callq 0x82fd0
jmp 0x952a1
jmp 0x952a3
jmp 0x952a5
leaq 0xef455(%rip), %rdi     # 0x184701
movl $0x1fb, %esi            # imm = 0x1FB
callq 0x82fd0
leaq 0xf39af(%rip), %rdi     # 0x188c6c
movl $0x1f9, %esi            # imm = 0x1F9
callq 0x82fd0
jmp 0x957ac
leaq 0x1e27dd(%rip), %rax    # 0x277ab0
cmpq $0x8000000, (%rax)      # imm = 0x8000000
jne 0x9531f
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x952f1
movl $0x1, %edi
callq 0x957e0
jmp 0x9531a
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x95303
xorl %edi, %edi
callq 0x95850
jmp 0x95318
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x95316
movl $0x3, %edi
callq 0x95850
jmp 0x95318
jmp 0x9531a
jmp 0x957aa
leaq 0x1e278a(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0x953c2
leaq 0x1e4e8e(%rip), %rax    # 0x27a1c8
cmpl $0x4f, (%rax)
jne 0x95379
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x9535b
leaq 0xef3b6(%rip), %rdi     # 0x184705
movl $0xfc, %esi
callq 0x82fd0
jmp 0x95377
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x95375
leaq 0xef3a8(%rip), %rdi     # 0x184713
movl $0xfc, %esi
callq 0x82fd0
jmp 0x95377
jmp 0x953b3
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x95395
leaq 0xef399(%rip), %rdi     # 0x184722
movl $0xfc, %esi
callq 0x82fd0
jmp 0x953b1
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x953af
leaq 0xef385(%rip), %rdi     # 0x18472a
movl $0xfc, %esi
callq 0x82fd0
jmp 0x953b1
jmp 0x953b3
movl $0x2297, %edi           # imm = 0x2297
callq 0x8c270
jmp 0x957a8
leaq 0x1e26e7(%rip), %rax    # 0x277ab0
cmpq $0x10, (%rax)
jne 0x954e7
jmp 0x953d5
leaq 0x208194(%rip), %rax    # 0x29d570
cmpq $0x0, (%rax)
je 0x953fe
leaq 0x208187(%rip), %rax    # 0x29d570
movq (%rax), %rdi
movzbl -0x1(%rbp), %edx
leaq 0xef33b(%rip), %rsi     # 0x184732
movb $0x0, %al
callq 0x9550
xorps %xmm0, %xmm0
callq 0x88f10
leaq 0x1e4db3(%rip), %rax    # 0x27a1c0
cmpl $0x4e, (%rax)
jne 0x9547b
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x9542e
leaq 0xef31f(%rip), %rdi     # 0x184741
movl $0x16, %esi
callq 0x82fd0
jmp 0x95468
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x9544a
leaq 0xef316(%rip), %rdi     # 0x184754
movl $0x16, %esi
callq 0x82fd0
jmp 0x95466
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x95464
leaq 0xeea98(%rip), %rdi     # 0x183ef2
movl $0x21, %esi
callq 0x82fd0
jmp 0x95466
jmp 0x95468
leaq 0xef30f(%rip), %rdi     # 0x18477e
movl $0x16, %esi
callq 0x82fd0
jmp 0x954e2
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x95497
leaq 0xeeae3(%rip), %rdi     # 0x183f6e
movl $0x16, %esi
callq 0x82fd0
jmp 0x954d1
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x954b3
leaq 0xef2bc(%rip), %rdi     # 0x184763
movl $0x16, %esi
callq 0x82fd0
jmp 0x954cf
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x954cd
leaq 0xef2b0(%rip), %rdi     # 0x184773
movl $0x21, %esi
callq 0x82fd0
jmp 0x954cf
jmp 0x954d1
leaq 0xef2a5(%rip), %rdi     # 0x18477d
movl $0x16, %esi
callq 0x82fd0
jmp 0x957a6
leaq 0x1e25c2(%rip), %rax    # 0x277ab0
cmpq $0x8, (%rax)
jne 0x95606
leaq 0x1e4cc1(%rip), %rax    # 0x27a1c0
cmpl $0x50, (%rax)
jne 0x95509
jmp 0x953d5
leaq 0x1e4cb0(%rip), %rax    # 0x27a1c0
cmpl $0x53, (%rax)
jne 0x9558b
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x95531
leaq 0xeea4a(%rip), %rdi     # 0x183f6f
movl $0x16, %esi
callq 0x82fd0
jmp 0x95589
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x9554d
leaq 0xef223(%rip), %rdi     # 0x184764
movl $0x16, %esi
callq 0x82fd0
jmp 0x95587
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x95569
leaq 0xef207(%rip), %rdi     # 0x184764
movl $0x16, %esi
callq 0x82fd0
jmp 0x95585
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x95583
leaq 0xee9f6(%rip), %rdi     # 0x183f6f
movl $0x16, %esi
callq 0x82fd0
jmp 0x95585
jmp 0x95587
jmp 0x95589
jmp 0x955ff
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
je 0x9559d
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x955b4
leaq 0x2d6644(%rip), %rax    # 0x36bbe8
movsd (%rax), %xmm0
movl $0x14, %edi
callq 0x94640
jmp 0x955fd
movzbl -0x1(%rbp), %eax
cmpl $0x1, %eax
je 0x955cf
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
je 0x955cf
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x955fb
leaq 0xef1b7(%rip), %rdi     # 0x18478d
movl $0x68, %esi
callq 0x82fd0
leaq 0xef025(%rip), %rdi     # 0x18460c
movl $0x67, %esi
callq 0x82fd0
leaq 0x2d707f(%rip), %rax    # 0x36c677
movb $0x4, (%rax)
jmp 0x955fd
jmp 0x955ff
jmp 0x95601
jmp 0x957a4
leaq 0x1e24a3(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x9571c
leaq 0x1e2492(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x95641
leaq 0x1e4b89(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x95641
leaq 0x1e24a1(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x95641
jmp 0x957d2
leaq 0x1e2468(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x95677
leaq 0x1e4b5f(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x95677
leaq 0x1e2477(%rip), %rax    # 0x277ad8
cmpl $0x33, (%rax)
je 0x95672
leaq 0x1e246b(%rip), %rax    # 0x277ad8
cmpl $0x47, (%rax)
jne 0x95677
jmp 0x957d2
leaq 0x1e2432(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x95695
leaq 0x1e4b29(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x95695
jmp 0x957d2
leaq 0x1e2414(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x956b3
leaq 0x1e4b0b(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
jne 0x956b3
jmp 0x957d2
leaq 0x1e23f6(%rip), %rax    # 0x277ab0
cmpq $0x1, (%rax)
jne 0x956f5
leaq 0x1e4aed(%rip), %rax    # 0x27a1b4
cmpl $0x36, (%rax)
je 0x956f0
leaq 0x1e4ae1(%rip), %rax    # 0x27a1b4
cmpl $0x33, (%rax)
je 0x956f0
leaq 0x1e4ad5(%rip), %rax    # 0x27a1b4
cmpl $0x50, (%rax)
je 0x956f0
leaq 0x1e4ac9(%rip), %rax    # 0x27a1b4
cmpl $0x41, (%rax)
jne 0x956f5
jmp 0x957d2
movl $0x8e, %edi
callq 0x824f0
movl $0xa3, %edi
callq 0x7b210
movzbl -0x1(%rbp), %edi
callq 0x7b210
callq 0x82590
jmp 0x957a2
leaq 0x1e238d(%rip), %rax    # 0x277ab0
cmpq $0x2000000, (%rax)      # imm = 0x2000000
jne 0x957a0
movzbl -0x1(%rbp), %eax
cmpl $0x2, %eax
jne 0x9573e
xorl %edi, %edi
callq 0x958c0
jmp 0x9579e
movzbl -0x1(%rbp), %eax
cmpl $0x4, %eax
jne 0x95750
xorl %edi, %edi
callq 0x958c0
jmp 0x9579c
movzbl -0x1(%rbp), %eax
cmpl $0x3, %eax
jne 0x95765
movl $0x1, %edi
callq 0x958c0
jmp 0x9579a
movzbl -0x1(%rbp), %eax
cmpl $0x5, %eax
jne 0x9577a
movl $0x1, %edi
callq 0x958c0
jmp 0x95798
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x95796
leaq 0x1e4852(%rip), %rax    # 0x279fdc
movl (%rax), %edi
movl $0x4, %esi
callq 0x95a50
jmp 0x95798
jmp 0x9579a
jmp 0x9579c
jmp 0x9579e
jmp 0x957a0
jmp 0x957a2
jmp 0x957a4
jmp 0x957a6
jmp 0x957a8
jmp 0x957aa
jmp 0x957ac
jmp 0x957ae
movzbl -0x1(%rbp), %eax
cmpl $0x0, %eax
jne 0x957d2
leaq 0x1e4c32(%rip), %rax    # 0x27a3f0
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x2088f8(%rip), %rax    # 0x29e0c4
movl $0x0, (%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)