// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, -0x38(%rbp)
leaq 0x273bdc(%rip), %rbx    # 0x2f773c
movl (%rbx), %r14d
leaq 0x273972(%rip), %rax    # 0x2f74dc
movl (%rax), %edi
leaq 0x273965(%rip), %rax    # 0x2f74d8
movl (%rax), %esi
leaq 0x273958(%rip), %rax    # 0x2f74d4
movl (%rax), %edx
callq 0xc2f07
movsd %xmm0, -0x30(%rbp)
leaq 0x273941(%rip), %rax    # 0x2f74d0
movl (%rax), %edi
leaq 0x273934(%rip), %rax    # 0x2f74cc
movl (%rax), %esi
leaq 0x273927(%rip), %r12    # 0x2f74c8
movl (%r12), %edx
xorpd %xmm0, %xmm0
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
movl (%rbx), %eax
movsd 0x71e43(%rip), %xmm1    # 0xf5a00
movsd -0x38(%rbp), %xmm2
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
subl %ecx, %eax
leaq 0x273b6d(%rip), %rcx    # 0x2f7740
movl %eax, (%rcx)
leaq 0x273b68(%rip), %rcx    # 0x2f7744
movl %eax, (%rcx)
movl %eax, (%rbx)
movapd %xmm2, %xmm1
divsd 0x6f444(%rip), %xmm1    # 0xf3030
addsd %xmm1, %xmm0
callq 0x55392
leaq 0x27391c(%rip), %rax    # 0x2f7518
movsd 0x84adc(%rip), %xmm0    # 0x1086e0
ucomisd (%rax), %xmm0
jb 0x83c24
leaq 0x2738cf(%rip), %rcx    # 0x2f74e0
andq $0x0, (%rcx)
leaq 0x273a9c(%rip), %rcx    # 0x2f76b8
andq $0x0, (%rcx)
andq $0x0, (%rax)
leaq 0x273ae5(%rip), %r15    # 0x2f7710
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x273adc(%rip), %r13    # 0x2f7718
movsd (%r13), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x273aa2(%rip), %rbx    # 0x2f76f0
movl $0x1, (%rbx)
movl (%r12), %eax
cmpl 0xd0712(%rip), %eax     # 0x154370
je 0x83c87
leaq 0x1817f9(%rip), %r12    # 0x205460
movsd (%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
andq $0x0, (%r12)
callq 0x694f6
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r12)
andl $0x0, (%rbx)
leaq 0x27386f(%rip), %rax    # 0x2f7500
cmpl $0x20, (%rax)
jne 0x83cd5
leaq 0x17ec33(%rip), %rax    # 0x2028d0
movq (%rax), %rax
cmpq $0x10, %rax
je 0x83cb7
cmpq $0x8, %rax
jne 0x83cc6
leaq 0x8a423(%rip), %rdi     # 0x10e0d6
pushq $0x65
jmp 0x83cc0
leaq 0x8a417(%rip), %rdi     # 0x10e0d5
pushq $0x11
popq %rsi
callq 0x576d4
callq 0x83b1e
movl $0x1, 0x2d2ef3(%rip)    # 0x356bc8
movsd -0x38(%rbp), %xmm0
mulsd 0x6f356(%rip), %xmm0    # 0xf3038
movsd -0x48(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r15)
addsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r13)
leaq 0x273a4e(%rip), %rax    # 0x2f7750
movq %r14, (%rax)
leaq 0x273a34(%rip), %rax    # 0x2f7740
movl %r14d, (%rax)
leaq 0x273a2e(%rip), %rax    # 0x2f7744
movl %r14d, (%rax)
leaq 0x273a1c(%rip), %rax    # 0x2f773c
movl %r14d, (%rax)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq