// File: jkingan[P]ladyheather/heathgps.cpp
// Function: fake_missing_second(double)
int fake_missing_second(double delta)
{
double jd;
double this_t,last_t;
static double last_jd = 0.0;
int old_yy;
int old_mm;
int old_dd;
int old_hh;
int old_min;
int old_sec;
u32 old_tow;
double old_frac;
double old_ro;


   // this routine generates a fake time message every other second in order
   // to support telecom receivers that work on 2 second intervals.
   // Returns 1 if call would cause a duplicated time stamp, else returns 0.

   old_yy = year;      // used to fake missing odd time time stamps
   old_mm = month;
   old_dd = day;
   old_hh = hours;
   old_min = minutes;
   old_sec = seconds;
   old_frac = raw_frac;
   old_tow = tow;

   jd = jdate(year,month,day);
   jd += jtime(hours,minutes,seconds, 0.000);  // !!!! raw_frac?
if(0 && debug_file) fprintf(debug_file, "fake missing:%04d/%02d/%02d  %02d:%02d:%02d\n", year,month,day, hours,minutes,seconds);

   last_jd = jd;

   tow = pri_tow = this_tow = (tow - (int) (delta-0.50));  // !!!!!! survey_tow?
   set_gregorian_time(jd - (delta / (24.0*60.0*60.0)));  // back up delta seconds
if(0 && debug_file) fprintf(debug_file, "faked missing:%04d/%02d/%02d  %02d:%02d:%02d\n", year,month,day, hours,minutes,seconds);
   if(pri_frac <= 0.002) {
      pri_frac = g_frac = raw_frac = 0.0;
   }

   this_t = this_time_msec;
   last_t = last_time_msec;

   if(rcvr_type == STAR_RCVR) {
      if(0 && debug_file && (seconds == (SCPI_STATUS_SECOND+1)) && (last_misc_second == (SCPI_STATUS_SECOND+2))) {
         fprintf(debug_file, "fake backsteped!\n");
         if(dbg_flush_mode) fflush(debug_file);
      }
   }

if(0 && debug_file) fprintf(debug_file, "fake missing: secs:%d  last:%d\n", seconds, last_misc_second);
   fake_time_stamp = 1;
   if(seconds != last_misc_second) {
      old_ro = rollover;   // disable rollover correction for faked seconds
      rollover = 0.0;
      update_gps_screen(554);
      rollover = old_ro;
if(0 && debug_file) fprintf(debug_file, "fake missing: updated  secs:%d  last:%d\n", seconds,last_misc_second);
   }
   fake_time_stamp = 0;

   if(pri_seconds == SCPI_STATUS_SECOND) {
     if(rcvr_type == UCCM_RCVR)  queue_uccm_cmd("SYST:STAT?", UCCM_STATUS_MSG);
     else if(rcvr_type == SCPI_RCVR) queue_scpi_cmd(":SYST:STAT?", SCPI_STATUS_MSG);
     start_fake_seconds(1);
     sent_uccm_status = 1;
   }

   this_time_msec = this_t + (1000.0 * delta);  // fake the timestamp of the faked time stamp message
   last_time_msec = last_t + (1000.0 * delta);

   if(0) {
      pri_year = year = old_yy;        // restore real time stamp
      pri_month = month = old_mm;
      pri_day = day = old_dd;
      pri_hours = hours = old_hh;
      pri_minutes = minutes = old_min;
      pri_seconds = seconds = old_sec;
      pri_frac = raw_frac = old_frac;
   }

   tow = pri_tow = this_tow = survey_tow = old_tow;  // !!!!!! survey_tow?
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movsd %xmm0, -0x8(%rbp)
leaq 0x2a67a8(%rip), %rax    # 0x36c6bc
movl (%rax), %eax
movl %eax, -0x24(%rbp)
leaq 0x2a6798(%rip), %rax    # 0x36c6b8
movl (%rax), %eax
movl %eax, -0x28(%rbp)
leaq 0x2a6788(%rip), %rax    # 0x36c6b4
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
leaq 0x2a6778(%rip), %rax    # 0x36c6b0
movl (%rax), %eax
movl %eax, -0x30(%rbp)
leaq 0x2a6768(%rip), %rax    # 0x36c6ac
movl (%rax), %eax
movl %eax, -0x34(%rbp)
leaq 0x2a6758(%rip), %rax    # 0x36c6a8
movl (%rax), %eax
movl %eax, -0x38(%rbp)
leaq 0x2a6764(%rip), %rax    # 0x36c6c0
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x2a69b0(%rip), %rax    # 0x36c91c
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
leaq 0x2a6744(%rip), %rax    # 0x36c6bc
movl (%rax), %edi
leaq 0x2a6737(%rip), %rax    # 0x36c6b8
movl (%rax), %esi
leaq 0x2a672a(%rip), %rax    # 0x36c6b4
movl (%rax), %edx
callq 0x122140
movsd %xmm0, -0x10(%rbp)
leaq 0x2a6713(%rip), %rax    # 0x36c6b0
movl (%rax), %edi
leaq 0x2a6706(%rip), %rax    # 0x36c6ac
movl (%rax), %esi
leaq 0x2a66f9(%rip), %rax    # 0x36c6a8
movl (%rax), %edx
xorps %xmm0, %xmm0
callq 0x122210
addsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, 0x30b0c0(%rip)   # 0x3d1090
leaq 0x2a6945(%rip), %rax    # 0x36c91c
movl (%rax), %ecx
movsd -0x8(%rbp), %xmm0
movsd 0xa90aa(%rip), %xmm1    # 0x16f090
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
subl %eax, %ecx
leaq 0x2a6929(%rip), %rax    # 0x36c920
movl %ecx, (%rax)
leaq 0x2a6924(%rip), %rax    # 0x36c924
movl %ecx, (%rax)
leaq 0x2a6913(%rip), %rax    # 0x36c91c
movl %ecx, (%rax)
movsd -0x10(%rbp), %xmm0
movsd -0x8(%rbp), %xmm1
movsd 0xa8feb(%rip), %xmm2    # 0x16f008
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
callq 0x7fb00
movsd 0xbd006(%rip), %xmm0    # 0x183038
leaq 0x2a66bf(%rip), %rax    # 0x36c6f8
ucomisd (%rax), %xmm0
jb 0xc6069
leaq 0x2a667a(%rip), %rax    # 0x36c6c0
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x2a6844(%rip), %rax    # 0x36c898
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x2a6696(%rip), %rax    # 0x36c6f8
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq 0x2a6880(%rip), %rax    # 0x36c8f0
movsd (%rax), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq 0x2a6878(%rip), %rax    # 0x36c8f8
movsd (%rax), %xmm0
movsd %xmm0, -0x20(%rbp)
leaq 0x1b1a20(%rip), %rax    # 0x277ab0
cmpq $0x1000, (%rax)         # imm = 0x1000
jne 0xc609b
jmp 0xc609b
leaq 0x2a682e(%rip), %rax    # 0x36c8d0
movl $0x1, (%rax)
leaq 0x2a65f9(%rip), %rax    # 0x36c6a8
movl (%rax), %eax
cmpl 0x1032a9(%rip), %eax    # 0x1c9360
je 0xc60f1
leaq 0x1b4580(%rip), %rax    # 0x27a640
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq 0x1b4570(%rip), %rax    # 0x27a640
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movl $0x22a, %edi            # imm = 0x22A
callq 0x9d790
movsd -0x50(%rbp), %xmm0
leaq 0x1b4553(%rip), %rax    # 0x27a640
movsd %xmm0, (%rax)
leaq 0x2a67d8(%rip), %rax    # 0x36c8d0
movl $0x0, (%rax)
leaq 0x2a65db(%rip), %rax    # 0x36c6e0
cmpl $0x20, (%rax)
jne 0xc615e
leaq 0x1b199f(%rip), %rax    # 0x277ab0
cmpq $0x8, (%rax)
jne 0xc612a
leaq 0xc135d(%rip), %rdi     # 0x18747b
movl $0x65, %esi
callq 0x82fd0
jmp 0xc614a
leaq 0x1b197f(%rip), %rax    # 0x277ab0
cmpq $0x10, (%rax)
jne 0xc6148
leaq 0xc133c(%rip), %rdi     # 0x18747a
movl $0x11, %esi
callq 0x82fd0
jmp 0xc614a
movl $0x1, %edi
callq 0xc5ec0
movl $0x1, 0x305c3a(%rip)    # 0x3cbd98
movsd -0x18(%rbp), %xmm1
movsd -0x8(%rbp), %xmm0
movsd 0xa8ec0(%rip), %xmm2    # 0x16f030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x2a6771(%rip), %rax    # 0x36c8f0
movsd %xmm0, (%rax)
movsd -0x20(%rbp), %xmm1
movsd -0x8(%rbp), %xmm0
movsd 0xa8e9b(%rip), %xmm2    # 0x16f030
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
leaq 0x2a6754(%rip), %rax    # 0x36c8f8
movsd %xmm0, (%rax)
movl -0x3c(%rbp), %eax
leaq 0x2a677e(%rip), %rcx    # 0x36c930
movq %rax, (%rcx)
movl %eax, %ecx
leaq 0x2a6762(%rip), %rax    # 0x36c920
movl %ecx, (%rax)
leaq 0x2a675d(%rip), %rax    # 0x36c924
movl %ecx, (%rax)
leaq 0x2a674c(%rip), %rax    # 0x36c91c
movl %ecx, (%rax)
xorl %eax, %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)