// File: /workspace/github_cpp_makefile_star2_O3/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 0x27cdff(%rip), %rbx    # 0x30d73c
movl (%rbx), %r14d
leaq 0x27cb95(%rip), %rax    # 0x30d4dc
movl (%rax), %edi
leaq 0x27cb88(%rip), %rax    # 0x30d4d8
movl (%rax), %esi
leaq 0x27cb7b(%rip), %rax    # 0x30d4d4
movl (%rax), %edx
callq 0xd485e
movsd %xmm0, -0x30(%rbp)
leaq 0x27cb64(%rip), %rax    # 0x30d4d0
movl (%rax), %edi
leaq 0x27cb57(%rip), %rax    # 0x30d4cc
movl (%rax), %esi
leaq 0x27cb4a(%rip), %r12    # 0x30d4c8
movl (%r12), %edx
xorpd %xmm0, %xmm0
callq 0xd492e
addsd -0x30(%rbp), %xmm0
movl (%rbx), %eax
movsd 0x7afee(%rip), %xmm1    # 0x10b988
movsd -0x38(%rbp), %xmm2
addsd %xmm2, %xmm1
cvttsd2si %xmm1, %ecx
subl %ecx, %eax
leaq 0x27cd90(%rip), %rcx    # 0x30d740
movl %eax, (%rcx)
leaq 0x27cd8b(%rip), %rcx    # 0x30d744
movl %eax, (%rcx)
movl %eax, (%rbx)
movapd %xmm2, %xmm1
divsd 0x78667(%rip), %xmm1    # 0x109030
addsd %xmm1, %xmm0
callq 0x5c71d
leaq 0x27cb3f(%rip), %rax    # 0x30d518
movsd 0x8dd87(%rip), %xmm0    # 0x11e768
ucomisd (%rax), %xmm0
jb 0x90a00
leaq 0x27caf2(%rip), %rcx    # 0x30d4e0
xorl %edx, %edx
movq %rdx, (%rcx)
leaq 0x27ccbe(%rip), %rcx    # 0x30d6b8
movq %rdx, (%rcx)
movq %rdx, (%rax)
leaq 0x27cd09(%rip), %r15    # 0x30d710
movsd (%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
leaq 0x27cd00(%rip), %r13    # 0x30d718
movsd (%r13), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x27ccc6(%rip), %rbx    # 0x30d6f0
movl $0x1, (%rbx)
movl (%r12), %eax
cmpl 0xd9936(%rip), %eax     # 0x16a370
je 0x90a66
leaq 0x18aa1d(%rip), %r12    # 0x21b460
movsd (%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
movq $0x0, (%r12)
callq 0x730e8
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r12)
movl $0x0, (%rbx)
leaq 0x27ca8d(%rip), %rax    # 0x30d500
cmpl $0x20, (%rax)
jne 0x90ad9
leaq 0x187e51(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x10, %rax
je 0x90a9c
cmpq $0x8, %rax
jne 0x90aad
leaq 0x936f9(%rip), %rdi     # 0x12418e
movl $0x65, %esi
jmp 0x90aa8
leaq 0x936ea(%rip), %rdi     # 0x12418d
movl $0x11, %esi
callq 0x5edda
callq 0xae92
addsd 0x7857e(%rip), %xmm0    # 0x109038
leaq 0x27cc37(%rip), %rax    # 0x30d6f8
movsd %xmm0, (%rax)
movl $0x0, 0x2e1389(%rip)    # 0x371e58
movl $0x1, 0x2dc0ef(%rip)    # 0x36cbc8
movsd -0x38(%rbp), %xmm0
mulsd 0x78552(%rip), %xmm0    # 0x109038
movsd -0x48(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r15)
addsd -0x30(%rbp), %xmm0
movsd %xmm0, (%r13)
leaq 0x27cc4a(%rip), %rax    # 0x30d750
movq %r14, (%rax)
leaq 0x27cc30(%rip), %rax    # 0x30d740
movl %r14d, (%rax)
leaq 0x27cc2a(%rip), %rax    # 0x30d744
movl %r14d, (%rax)
leaq 0x27cc18(%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