// File: jkingan[P]ladyheather/heathgps.cpp
// Function: x72_slopecalc_state()
void x72_slopecalc_state()
{
double slope;
double intercept;
double freq_change;
static int changes = 0;

   // calculate the frequency drift rate during holdover and adjust the DDS
   if(pps_enabled == 0) {  // should never happen
      x72_start_discipline();
      return;
   }

   slope = ((double) x72_idif_sum) / (double) x72_holdover_points;
   slope /= (double) x72_osc;
   intercept = 0.0;   // !!!!! calc intercept

   if(1 && (x72_jamsync_flag > 1)) ;  // we are forcing a jam sync
   else x72_jamsync_flag = 0;

   x72_jamsync_pass = 1;
   x72_jamsync_ticks = 0;
   x72_holdover_points = 0;
//sprintf(debug_text2, "calc slope: %g  intercept:%g  last_dds:%g  startup:%d", slope, intercept, last_x72_dds, x72_startup_flag);

   if(0 && (fabs(slope) > 300.0E-9)) {
      x72_user_state = X72_STATE_HOLDOVER;
      x72_pps_diff = 0;
      return;
   }

   if(x72_startup_flag) {    // first time through after starting disciplining
      x72_jamsync_flag = 2;  // force a PPS jam sync
   }
   x72_startup_flag = 0;

   if(x72_startup_flag == 0) {
      if(slope) {
         freq_change = last_x72_dds + slope;
         last_interval_dds = interval_start_dds;
         interval_start_dds = freq_change;
         set_x72_dds(freq_change);
         ++changes;
         have_x72_pps = 0;
         x72_jamsync_flag = 2;
      }
      x72_user_state = X72_STATE_JAM1;
      return;
   }

   x72_startup_flag = 0;
///   if(intercept > 1.0E-6) {  // !!!!!!
   if(IABS(fix_x72_tics(x72_pps)) > (int) (1000.0*1.0E-9*x72_osc)) { // pps is off by over 1us... we need to adjust the TIC offset register
////      x72_jamsync_flag = 1;
   }

   x72_user_state = X72_STATE_JAM1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0x2629d1(%rip), %rax    # 0x36cf00
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x10a541
callq 0xc4ec0
jmp 0x10a6c9
cvtsi2sdl 0x2cb2fb(%rip), %xmm0 # 0x3d5844
cvtsi2sdl 0x2cb2ff(%rip), %xmm1 # 0x3d5850
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
leaq 0x16f8e7(%rip), %rax    # 0x279e48
movsd (%rax), %xmm1
movsd -0x8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
cmpl $0x1, 0x2cb2d6(%rip)    # 0x3d5858
jle 0x10a586
jmp 0x10a590
movl $0x0, 0x2cb2c8(%rip)    # 0x3d5858
movl $0x1, 0x2cb2c6(%rip)    # 0x3d5860
movl $0x0, 0x2cb2b8(%rip)    # 0x3d585c
movl $0x0, 0x2cb2a2(%rip)    # 0x3d5850
cmpl $0x0, 0xbf07b(%rip)     # 0x1c9630
je 0x10a5c1
movl $0x2, 0x2cb297(%rip)    # 0x3d5858
movl $0x0, 0xbf065(%rip)     # 0x1c9630
cmpl $0x0, 0xbf05e(%rip)     # 0x1c9630
jne 0x10a658
movsd -0x8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x10a5ea
jp 0x10a5ea
jmp 0x10a64c
leaq 0x16facf(%rip), %rax    # 0x27a0c0
movsd (%rax), %xmm0
addsd -0x8(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd 0x2cb271(%rip), %xmm0   # 0x3d5878
movsd %xmm0, 0x2cb271(%rip)   # 0x3d5880
movsd -0x18(%rbp), %xmm0
movsd %xmm0, 0x2cb25c(%rip)   # 0x3d5878
movsd -0x18(%rbp), %xmm0
callq 0x9a4f0
movl 0x2ce954(%rip), %eax    # 0x3d8f80
addl $0x1, %eax
movl %eax, 0x2ce94b(%rip)    # 0x3d8f80
leaq 0x16f874(%rip), %rax    # 0x279eb0
movl $0x0, (%rax)
movl $0x2, 0x2cb20c(%rip)    # 0x3d5858
movl $0x4, 0x2c175e(%rip)    # 0x3cbdb4
jmp 0x10a6c9
movl $0x0, 0xbefce(%rip)     # 0x1c9630
leaq 0x16f973(%rip), %rax    # 0x279fdc
movl (%rax), %edi
callq 0xc4890
cmpl $0x0, %eax
jge 0x10a68e
leaq 0x16f960(%rip), %rax    # 0x279fdc
movl (%rax), %edi
callq 0xc4890
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
jmp 0x10a69f
leaq 0x16f947(%rip), %rax    # 0x279fdc
movl (%rax), %edi
callq 0xc4890
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movsd 0x78c46(%rip), %xmm0    # 0x1832f0
leaq 0x16f797(%rip), %rcx    # 0x279e48
mulsd (%rcx), %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
jle 0x10a6bf
jmp 0x10a6bf
movl $0x4, 0x2c16eb(%rip)    # 0x3cbdb4
addq $0x20, %rsp
popq %rbp
retq
nop