// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: primary_misc()
void primary_misc()
{
   //  This routine is called once a time stamp message has been received.
   //  It handles time conversions, event handling, etc.
   //

   last_misc_second = seconds;

   if(time_flags & TFLAGS_UTC) {  // receiver time is in UTC
      jd_gps = jd_utc + jtime(0,0,utc_offset,0.0);
   }
   else {  // receiver time is in GPS - convert GPS time to UTC time
      jd_utc -= jtime(0,0,utc_offset,0.0);
   }

   jd_tt = jd_gps + utc_delta_t() - jtime(0,0,0,((double) utc_offset)+TSX_TWEAK);  // TT is 51.184 seconds ahead of GPS

   jd_local = jd_utc + time_zone() + jtime(0,0,0,TSX_TWEAK);  // local time (UTC adjusted for time zone)
   gregorian(0, jd_local);
   this_year = g_year;  // the current year in the local time zone

   have_time = 1;
   if(have_year != year) {    // it's the first valid year we have seen or year has changed
      have_year = year;
      init_dsm(this_year);    // tweek month tables for possible leap year
      calc_dst_times(this_year, dst_list[dst_area]);  // find daylight savings change times
      calc_dst_times(this_year, dst_list[dst_area]);  // do it again to get things right if starting up near DST switch time
   }                                       // and recalculate the seasons, etc

   ticker ^= 1;               // used to flash the alarm on the screen
   adjust_tz(10);             // tweak pri_xxxx time variables for time zone and daylight savings time

   if(hours != last_hours) {
      dst_ofs = dst_offset();
      jd_local = jd_utc + time_zone() + jtime(0,0,0,TSX_TWEAK);
      last_hours = hours;
   }

   have_sun_el = 0;
   eclipsed = 0;
   if((lat != 0.0) || (lon != 0.0)) {
      sun_el = sun_posn(jd_utc, 0);   // calculate sun position
      set_sat_azel(SUN_PRN, (float) sun_az, (float) sun_el);
      have_sun_el = 1;
      log_sun_posn();

      moon_posn(jd_tt);               // calculate moon position
      if(need_posns > 0) --need_posns;
      eclipse();
   }

   if(realtime_sun || need_sunrise || ((pri_minutes == 00) && (pri_seconds == SUN_SECOND))) {  // update sunrise time
      if(have_utc_ofs) {
         if(do_moonrise) calc_moonrise();
         else            calc_sunrise(0.0, 20);
         if((lat != 0.0) || (lon != 0.0) || NO_SATS) {
            need_sunrise = 0;
         }
      }
   }

   moon_info(jd_utc);       // calculate moon phase, etc

   #ifdef SAT_TRAILS
      update_sat_trails();  // update sat az/el position array
   #endif


   if(set_time_minutely) {  // we do it a xx:xx:06 local time every minute
      if(pri_seconds == SYNC_SECOND) {
         need_time_set();
      }
   }
   else if(set_time_hourly) {  // we do it a xx:05:06 local time every hour
      if((pri_minutes == SYNC_MINUTE) && (pri_seconds == SYNC_SECOND)) {
         need_time_set();
      }
   }
   else if(set_time_daily) {  // we do it a 4:05:06 local time every day
      if((pri_hours == SYNC_HOUR) && (pri_minutes == SYNC_MINUTE) && (pri_seconds == SYNC_SECOND)) {
         need_time_set();
      }
   }

   set_cpu_clock();           // set system clock to receiver time

   // Apparently some X11 libs have an internal 32 bit counter that
   // causes a "resource temporarily unavailable" exit when it overflows.
   // Here we periodically re-init the screen in an attempt to prevent
   // this from happening.  The counter overflow seems to happen after
   // several days to weeks so we re-init the screen once a day.
   // Also, we rebuild the lla scattergram plot from plot queue data
   // so it remains "fresh".  The screen re-init is only done if the keyboard
   // has been idle for over REINIT_IDLE_TIME seconds.

   if(reinit_jd == 0.0) reinit_jd = (jd_utc + REINIT_INTERVAL);
   if((jd_utc > reinit_jd) && (idle_time >= REINIT_IDLE_TIME) && (pri_seconds == REINIT_SECOND)) {
      reinit_jd = (jd_utc + REINIT_INTERVAL);
      #ifdef USE_X11
         init_screen(9101);
         need_redraw = 9101;
      #endif

      rebuild_lla_plot(0);  // keep LLA plot fresh
   }

   #ifdef GREET_STUFF
      if(new_moon_info || (pri_day != last_day)) {    // calculate new moon info for the month
         if(new_moon_info || (pri_seconds == MOON_STUFF)) {
            calc_moons(jd_local, 10);
            last_day = pri_day;
            new_moon_info = 0;

            if(MAX_AVG_COUNT == 0.0F) {  // keep signal level info fresh
               freshen_sig_info();       // restart signal averaging from the current averages
            }
         }
      }
   #endif

   greet_on = 1;        // it's now OK to calculate greetings
   get_delta_t();       // try to get delta_t from external file deltat.dat
   check_end_times();   // exit program at preset time

   silly_clocks();      // do alarm clock and cuckoo clock
   grav_force(jd_utc);  // calculate gravity and earth tides
   show_satinfo();      // show satellite info
   dump_prn_info();     // write sat PRN az/el/sig level file if open
   draw_maps();         // draw maps and analog watch

   echo_nmea();         // if NMEA echo is enabled sent out NMEA formatted data

   if(time_flags != last_time_flags) {     // redo big clock if time settings have changed
      sync_log_file();  // time reference changed,  note it in the log file
      last_time_flags = time_flags;
   }

   if(set_gps_mode || set_utc_mode) {
      if(luxor) {
         if(set_gps_mode) time_flags |= TFLAGS_UTC;
         else if(set_utc_mode) time_flags &= (~TFLAGS_UTC);
      }

      if(time_flags & TFLAGS_UTC) {  // we are in UTC mode
         if(set_gps_mode) set_timing_mode(TMODE_GPS, 10);
         set_utc_mode = set_gps_mode = 0;
      }
      else { // we are in GPS mode
         if(set_utc_mode) set_timing_mode(TMODE_UTC, 11);
         set_utc_mode = set_gps_mode = 0;
      }
   }

   show_time_info();   // draw primary timing data
   if(configed_mode == RCVR_MODE_DGPS) {   // secondary timing not available in DGPS mode
      refresh_page();
   }

   if(user_fix_set) {  // command line option enabled fix map display
      config_fix_display();
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x2a3f12(%rip), %rax    # 0x2f74c8
movl (%rax), %eax
movl %eax, 0x100db2(%rip)    # 0x154370
leaq 0x2a3edf(%rip), %rax    # 0x2f74a4
testb $0x1, (%rax)
jne 0x53605
leaq 0x2a4157(%rip), %rax    # 0x2f7728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xc2faf
leaq 0x2a3f49(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax)
leaq 0x2a3f3e(%rip), %rax    # 0x2f7538
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x53640
leaq 0x2a3f24(%rip), %rax    # 0x2f7530
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2a410c(%rip), %rax    # 0x2f7728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
leaq 0x2a3f01(%rip), %rax    # 0x2f7538
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, (%rax)
callq 0xbcc92
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2a40d2(%rip), %rax    # 0x2f7728
cvtsi2sdl (%rax), %xmm1
leaq 0x2a4867(%rip), %r13    # 0x2f7ec8
movsd (%r13), %xmm0
divsd 0x9f9c9(%rip), %xmm0    # 0xf3038
addsd %xmm1, %xmm0
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x2a3eb2(%rip), %r12    # 0x2f7540
movsd %xmm1, (%r12)
leaq 0x2a3e95(%rip), %r14    # 0x2f7530
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xce627
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0x9f976(%rip), %xmm0    # 0xf3038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
leaq 0x2a3e6f(%rip), %rax    # 0x2f7548
movsd %xmm0, (%rax)
xorl %edi, %edi
callq 0xbfac2
leaq 0x2a3fb9(%rip), %rax    # 0x2f76a4
movl (%rax), %edi
leaq 0x2a3e2c(%rip), %rbx    # 0x2f7520
movl %edi, (%rbx)
leaq 0x1d57df(%rip), %rax    # 0x228edc
movb $0x1, (%rax)
leaq 0x1d57d9(%rip), %rax    # 0x228ee0
leaq 0x2a3dce(%rip), %rcx    # 0x2f74dc
movl (%rcx), %ecx
cmpl %ecx, (%rax)
je 0x53758
movl %ecx, (%rax)
callq 0xcd74f
movl (%rbx), %edi
leaq 0x2a4178(%rip), %r15    # 0x2f789c
movslq (%r15), %rax
movq %r12, %r13
movq %r14, %r12
leaq 0x1010fc(%rip), %r14    # 0x154830
movq (%r14,%rax,8), %rsi
callq 0xce1f2
movl (%rbx), %edi
movslq (%r15), %rax
movq (%r14,%rax,8), %rsi
movq %r12, %r14
movq %r13, %r12
leaq 0x2a4775(%rip), %r13    # 0x2f7ec8
callq 0xce1f2
leaq 0x2a4781(%rip), %rax    # 0x2f7ee0
xorb $0x1, (%rax)
pushq $0xa
popq %rdi
callq 0xcf298
leaq 0x2a3d5f(%rip), %rbx    # 0x2f74d0
movl (%rbx), %eax
leaq 0x2a3f86(%rip), %r15    # 0x2f7700
cmpl (%r15), %eax
je 0x537d4
callq 0xce4ef
leaq 0x2a4115(%rip), %rcx    # 0x2f78a0
movl %eax, (%rcx)
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xce627
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0x9f884(%rip), %xmm0    # 0xf3038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xc2faf
addsd -0x30(%rbp), %xmm0
leaq 0x2a3d7d(%rip), %rax    # 0x2f7548
movsd %xmm0, (%rax)
movl (%rbx), %eax
movl %eax, (%r15)
leaq 0x2a3fed(%rip), %r15    # 0x2f77c8
andl $0x0, (%r15)
leaq 0x2a402a(%rip), %rax    # 0x2f7810
andl $0x0, (%rax)
leaq 0x2a37e0(%rip), %rbx    # 0x2f6fd0
movsd (%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
leaq 0x2a37d5(%rip), %r13    # 0x2f6fd8
jne 0x53815
jp 0x53815
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x53815
jnp 0x53875
movsd (%r14), %xmm0
xorl %edi, %edi
callq 0xd3da7
leaq 0x2a3fa8(%rip), %rax    # 0x2f77d0
cvtsd2ss (%rax), %xmm2
leaq 0x2a3f85(%rip), %rax    # 0x2f77b8
movsd %xmm0, (%rax)
cvtsd2ss %xmm0, %xmm1
movl $0x3e8, %edi            # imm = 0x3E8
movaps %xmm2, %xmm0
callq 0x53b74
movl $0x1, (%r15)
callq 0xdfb15
movsd (%r12), %xmm0
callq 0xd3202
leaq 0x1b1b7a(%rip), %rax    # 0x2053e0
movb (%rax), %cl
testb %cl, %cl
je 0x53870
decb %cl
movb %cl, (%rax)
callq 0x53d09
leaq 0x2a3d38(%rip), %rax    # 0x2f75b4
leaq 0x2a3d2d(%rip), %r12    # 0x2f75b0
movl (%r12), %ecx
orl (%rax), %ecx
jne 0x538ab
leaq 0x2a3c72(%rip), %rax    # 0x2f7504
cmpl $0x0, (%rax)
jne 0x53942
leaq 0x2a3c5e(%rip), %rax    # 0x2f7500
cmpl $0x1a, (%rax)
jne 0x53942
leaq 0x2a3a6a(%rip), %rax    # 0x2f731c
cmpl $0x0, (%rax)
je 0x53942
leaq 0x2a3dbe(%rip), %rax    # 0x2f7680
cmpl $0x0, (%rax)
je 0x538ce
callq 0xd485d
jmp 0x538da
pushq $0x14
popq %rdi
xorpd %xmm0, %xmm0
callq 0xd4cfa
movsd (%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5393d
jp 0x5393d
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5393d
jp 0x5393d
leaq 0x1aefd1(%rip), %rax    # 0x2028d0
movq (%rax), %rax
movabsq $0x105b8b0400, %rcx     # imm = 0x105B8B0400
testq %rcx, %rax
jne 0x5393d
leaq 0x1b16b8(%rip), %rcx    # 0x204fd0
cmpl $0x0, (%rcx)
je 0x53929
leaq 0x2a3aa0(%rip), %rcx    # 0x2f73c4
cmpl $0x0, (%rcx)
je 0x5393d
cmpq $0x400000, %rax         # imm = 0x400000
jne 0x53942
leaq 0x2a407c(%rip), %rax    # 0x2f79b4
cmpl $0x0, (%rax)
jne 0x53942
andl $0x0, (%r12)
movsd (%r14), %xmm0
callq 0xd2b1b
callq 0xdf5bc
leaq 0x2a455c(%rip), %rax    # 0x2f7eb4
cmpb $0x0, (%rax)
jne 0x5398d
leaq 0x2a454f(%rip), %rax    # 0x2f7eb3
cmpb $0x0, (%rax)
jne 0x53981
leaq 0x2a4542(%rip), %rax    # 0x2f7eb2
cmpb $0x0, (%rax)
je 0x5399e
leaq 0x2a3b8c(%rip), %rax    # 0x2f7508
cmpl $0x4, (%rax)
jne 0x5399e
leaq 0x2a3b7c(%rip), %rax    # 0x2f7504
cmpl $0x5, (%rax)
jne 0x5399e
leaq 0x2a3b6c(%rip), %rax    # 0x2f7500
cmpl $0x6, (%rax)
jne 0x5399e
callq 0xd163c
callq 0xa74c
leaq 0x2a3dde(%rip), %rax    # 0x2f7788
movsd (%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movsd (%r14), %xmm0
jne 0x539cf
jp 0x539cf
movsd 0x9f6a9(%rip), %xmm1    # 0xf3070
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
ucomisd %xmm1, %xmm0
leaq 0x2a3b26(%rip), %rbx    # 0x2f7500
jbe 0x53a20
leaq 0x2a3bbd(%rip), %rcx    # 0x2f75a0
movsd (%rcx), %xmm1
ucomisd 0x9f6b9(%rip), %xmm1    # 0xf30a8
jb 0x53a20
cmpl $0x36, (%rbx)
jne 0x53a20
addsd 0x9f672(%rip), %xmm0    # 0xf3070
movsd %xmm0, (%rax)
movl $0x238d, %edi           # imm = 0x238D
callq 0xbc0b
leaq 0x1aee31(%rip), %rax    # 0x202844
movl $0x238d, (%rax)         # imm = 0x238D
xorl %edi, %edi
callq 0xe6975
leaq 0x2a3d69(%rip), %r15    # 0x2f7790
movl (%r15), %eax
testl %eax, %eax
jne 0x53a42
leaq 0x2a3ad7(%rip), %rcx    # 0x2f750c
movl (%rcx), %ecx
leaq 0x2a3d42(%rip), %rdx    # 0x2f7780
cmpl (%rdx), %ecx
je 0x53a79
testl %eax, %eax
jne 0x53a4b
cmpl $0x30, (%rbx)
jne 0x53a79
leaq 0x2a3af6(%rip), %rax    # 0x2f7548
movsd (%rax), %xmm0
pushq $0xa
popq %rdi
callq 0xd57b4
leaq 0x2a3aa7(%rip), %rax    # 0x2f750c
movl (%rax), %eax
leaq 0x2a3d12(%rip), %rcx    # 0x2f7780
movl %eax, (%rcx)
andl $0x0, (%r15)
callq 0xe3cb5
leaq 0x1aed74(%rip), %rax    # 0x2027f4
movl $0x1, (%rax)
callq 0xcffd7
callq 0xcfb72
callq 0xd098d
movsd (%r14), %xmm0
callq 0xd9a3b
callq 0x53e55
callq 0x545e2
callq 0xe23b2
callq 0x534ad
leaq 0x2a39ea(%rip), %r15    # 0x2f74a4
movl (%r15), %eax
leaq 0x2a39e4(%rip), %rbx    # 0x2f74a8
cmpl (%rbx), %eax
je 0x53ad2
callq 0xb2d82
movl (%r15), %eax
movl %eax, (%rbx)
leaq 0x2a39db(%rip), %rbx    # 0x2f74b4
movl (%rbx), %edx
leaq 0x2a39ce(%rip), %r14    # 0x2f74b0
movl (%r14), %ecx
movl %edx, %esi
orl %ecx, %esi
je 0x53b30
leaq 0x1d544c(%rip), %rsi    # 0x228f3e
cmpb $0x0, (%rsi)
je 0x53b01
testl %edx, %edx
je 0x53b15
orl $0x1, %eax
movl %eax, (%r15)
testb $0x1, %al
jne 0x53b0d
movb $0x3, %al
testl %ecx, %ecx
jne 0x53b21
jmp 0x53b29
testl %edx, %edx
je 0x53b29
xorl %eax, %eax
jmp 0x53b21
testl %ecx, %ecx
je 0x53b29
andl $-0x2, %eax
movl %eax, (%r15)
movb $0x3, %al
movzbl %al, %edi
callq 0x546d8
andl $0x0, (%rbx)
andl $0x0, (%r14)
callq 0x54be8
leaq 0x2a3596(%rip), %rax    # 0x2f70d2
cmpb $0x5, (%rax)
jne 0x53b46
callq 0xaa05
leaq 0x2d1788(%rip), %rax    # 0x3252d5
cmpb $0x0, (%rax)
je 0x53b65
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3818f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq