// File: /workspace/github_cpp_makefile_star2_O1/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 0x27ce6f(%rip), %rbx    # 0x30d73c
movl (%rbx), %r14d
leaq 0x27cc05(%rip), %rax    # 0x30d4dc
movl (%rax), %edi
leaq 0x27cbf8(%rip), %rax    # 0x30d4d8
movl (%rax), %esi
leaq 0x27cbeb(%rip), %rax    # 0x30d4d4
movl (%rax), %edx
callq 0xd4110
movsd %xmm0, -0x30(%rbp)
leaq 0x27cbd4(%rip), %rax    # 0x30d4d0
movl (%rax), %edi
leaq 0x27cbc7(%rip), %rax    # 0x30d4cc
movl (%rax), %esi
leaq 0x27cbba(%rip), %r12    # 0x30d4c8
movl (%r12), %edx
xorpd %xmm0, %xmm0
callq 0xd41e0
addsd -0x30(%rbp), %xmm0
movl (%rbx), %eax
movsd 0x7b056(%rip), %xmm1    # 0x10b980
movsd -0x38(%rbp), %xmm2
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
subl %ecx, %eax
leaq 0x27ce00(%rip), %rcx    # 0x30d740
movl %eax, (%rcx)
leaq 0x27cdfb(%rip), %rcx    # 0x30d744
movl %eax, (%rcx)
movl %eax, (%rbx)
movapd %xmm2, %xmm1
divsd 0x786d7(%rip), %xmm1    # 0x109030
addsd %xmm1, %xmm0
callq 0x5c837
leaq 0x27cbaf(%rip), %rax    # 0x30d518
movsd 0x8dd47(%rip), %xmm0    # 0x11e6b8
ucomisd (%rax), %xmm0
jb 0x90990
leaq 0x27cb62(%rip), %rcx    # 0x30d4e0
xorl %edx, %edx
movq %rdx, (%rcx)
leaq 0x27cd2e(%rip), %rcx    # 0x30d6b8
movq %rdx, (%rcx)
movq %rdx, (%rax)
leaq 0x27cd79(%rip), %r15    # 0x30d710
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x27cd70(%rip), %r13    # 0x30d718
movsd (%r13), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x27cd36(%rip), %rbx    # 0x30d6f0
movl $0x1, (%rbx)
movl (%r12), %eax
cmpl 0xd99a6(%rip), %eax     # 0x16a370
je 0x909f6
leaq 0x18aa8d(%rip), %r12    # 0x21b460
movsd (%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
movq $0x0, (%r12)
callq 0x7327e
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r12)
movl $0x0, (%rbx)
leaq 0x27cafd(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x90a69
leaq 0x187ec1(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x10, %rax
je 0x90a2c
cmpq $0x8, %rax
jne 0x90a3d
leaq 0x93689(%rip), %rdi     # 0x1240ae
movl $0x65, %esi
jmp 0x90a38
leaq 0x9367a(%rip), %rdi     # 0x1240ad
movl $0x11, %esi
callq 0x5ee52
callq 0xaea1
addsd 0x785ee(%rip), %xmm0    # 0x109038
leaq 0x27cca7(%rip), %rax    # 0x30d6f8
movsd %xmm0, (%rax)
movl $0x0, 0x2e13f9(%rip)    # 0x371e58
movl $0x1, 0x2dc15f(%rip)    # 0x36cbc8
movsd -0x38(%rbp), %xmm0
mulsd 0x785c2(%rip), %xmm0    # 0x109038
movsd -0x48(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r15)
addsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r13)
leaq 0x27ccba(%rip), %rax    # 0x30d750
movq %r14, (%rax)
leaq 0x27cca0(%rip), %rax    # 0x30d740
movl %r14d, (%rax)
leaq 0x27cc9a(%rip), %rax    # 0x30d744
movl %r14d, (%rax)
leaq 0x27cc88(%rip), %rax    # 0x30d73c
movl %r14d, (%rax)
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq