// File: /workspace/github_cpp_makefile_star2_O3/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 0x2b2db2(%rip), %rax    # 0x30d4c8
movl (%rax), %eax
movl %eax, 0x10fc52(%rip)    # 0x16a370
leaq 0x2b2d7f(%rip), %rax    # 0x30d4a4
testb $0x1, (%rax)
jne 0x5a765
leaq 0x2b2ff7(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd492e
leaq 0x2b2de9(%rip), %rax    # 0x30d530
movsd (%rax), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax)
leaq 0x2b2dde(%rip), %rax    # 0x30d538
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x5a7a0
leaq 0x2b2dc4(%rip), %rax    # 0x30d530
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2b2fac(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd492e
addsd -0x30(%rbp), %xmm0
leaq 0x2b2da1(%rip), %rax    # 0x30d538
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, (%rax)
callq 0xce380
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2b2f72(%rip), %rax    # 0x30d728
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
leaq 0x2b3704(%rip), %r13    # 0x30dec8
movsd (%r13), %xmm0
divsd 0xae866(%rip), %xmm0    # 0x109038
addsd %xmm1, %xmm0
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x2b2d4f(%rip), %r12    # 0x30d540
movsd %xmm1, (%r12)
leaq 0x2b2d32(%rip), %r14    # 0x30d530
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xe176a
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0xae813(%rip), %xmm0    # 0x109038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
addsd -0x30(%rbp), %xmm0
leaq 0x2b2d0c(%rip), %rax    # 0x30d548
movsd %xmm0, (%rax)
xorl %edi, %edi
callq 0xd12da
leaq 0x2b2e56(%rip), %rax    # 0x30d6a4
movl (%rax), %edi
leaq 0x2b2cc9(%rip), %rbx    # 0x30d520
movl %edi, (%rbx)
leaq 0x1e467c(%rip), %rax    # 0x23eedc
movb $0x1, (%rax)
leaq 0x1e4676(%rip), %rax    # 0x23eee0
leaq 0x2b2c6b(%rip), %rcx    # 0x30d4dc
movl (%rcx), %ecx
cmpl %ecx, (%rax)
je 0x5a8bb
movl %ecx, (%rax)
callq 0xe0736
movl (%rbx), %edi
leaq 0x2b3015(%rip), %r15    # 0x30d89c
movslq (%r15), %rax
movq %r14, %r13
movq %r12, %r14
leaq 0x10ff99(%rip), %r12    # 0x16a830
movq (%r12,%rax,8), %rsi
callq 0xe1326
movl (%rbx), %edi
movslq (%r15), %rax
movq (%r12,%rax,8), %rsi
movq %r14, %r12
movq %r13, %r14
leaq 0x2b3612(%rip), %r13    # 0x30dec8
callq 0xe1326
leaq 0x2b361e(%rip), %rax    # 0x30dee0
xorb $0x1, (%rax)
movl $0xa, %edi
callq 0xe2692
leaq 0x2b2bfa(%rip), %rbx    # 0x30d4d0
movl (%rbx), %eax
leaq 0x2b2e21(%rip), %r15    # 0x30d700
cmpl (%r15), %eax
je 0x5a939
callq 0xe1630
leaq 0x2b2fb0(%rip), %rcx    # 0x30d8a0
movl %eax, (%rcx)
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xe176a
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0xae71f(%rip), %xmm0    # 0x109038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd492e
addsd -0x30(%rbp), %xmm0
leaq 0x2b2c18(%rip), %rax    # 0x30d548
movsd %xmm0, (%rax)
movl (%rbx), %eax
movl %eax, (%r15)
leaq 0x2b2e88(%rip), %r15    # 0x30d7c8
xorl %eax, %eax
movl %eax, (%r15)
leaq 0x2b2ec4(%rip), %rcx    # 0x30d810
movl %eax, (%rcx)
leaq 0x2b267b(%rip), %rbx    # 0x30cfd0
movsd (%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
leaq 0x2b2670(%rip), %r13    # 0x30cfd8
jne 0x5a97a
jp 0x5a97a
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5a97a
jnp 0x5a9dd
movsd (%r14), %xmm0
xorl %edi, %edi
callq 0xe823e
leaq 0x2b2e43(%rip), %rax    # 0x30d7d0
cvtsd2ss (%rax), %xmm2
leaq 0x2b2e20(%rip), %rax    # 0x30d7b8
movsd %xmm0, (%rax)
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movl $0x3e8, %edi            # imm = 0x3E8
movaps %xmm2, %xmm0
callq 0x5ace1
movl $0x1, (%r15)
callq 0xf5054
movsd (%r12), %xmm0
callq 0xe7272
leaq 0x1c0a12(%rip), %rax    # 0x21b3e0
movb (%rax), %cl
testb %cl, %cl
je 0x5a9d8
decb %cl
movb %cl, (%rax)
callq 0x5ae78
leaq 0x2b2bd0(%rip), %rax    # 0x30d5b4
leaq 0x2b2bc5(%rip), %r12    # 0x30d5b0
movl (%r12), %ecx
orl (%rax), %ecx
jne 0x5aa13
leaq 0x2b2b0a(%rip), %rax    # 0x30d504
cmpl $0x0, (%rax)
jne 0x5aaaf
leaq 0x2b2af6(%rip), %rax    # 0x30d500
cmpl $0x1a, (%rax)
jne 0x5aaaf
leaq 0x2b2902(%rip), %rax    # 0x30d31c
cmpl $0x0, (%rax)
je 0x5aaaf
leaq 0x2b2c56(%rip), %rax    # 0x30d680
cmpl $0x0, (%rax)
je 0x5aa36
callq 0xe8d21
jmp 0x5aa44
xorpd %xmm0, %xmm0
movl $0x14, %edi
callq 0xe91e5
movsd (%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5aaa7
jp 0x5aaa7
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5aaa7
jp 0x5aaa7
leaq 0x1bde67(%rip), %rax    # 0x2188d0
movq (%rax), %rax
movabsq $0x105b8b0400, %rcx     # imm = 0x105B8B0400
testq %rcx, %rax
jne 0x5aaa7
leaq 0x1c054e(%rip), %rcx    # 0x21afd0
cmpl $0x0, (%rcx)
je 0x5aa93
leaq 0x2b2936(%rip), %rcx    # 0x30d3c4
cmpl $0x0, (%rcx)
je 0x5aaa7
cmpq $0x400000, %rax         # imm = 0x400000
jne 0x5aaaf
leaq 0x2b2f12(%rip), %rax    # 0x30d9b4
cmpl $0x0, (%rax)
jne 0x5aaaf
movl $0x0, (%r12)
movsd (%r14), %xmm0
callq 0xe6aa4
callq 0xf4ae1
leaq 0x2b33ef(%rip), %rax    # 0x30deb4
cmpb $0x0, (%rax)
jne 0x5aafa
leaq 0x2b33e2(%rip), %rax    # 0x30deb3
cmpb $0x0, (%rax)
jne 0x5aaee
leaq 0x2b33d5(%rip), %rax    # 0x30deb2
cmpb $0x0, (%rax)
je 0x5ab0b
leaq 0x2b2a1f(%rip), %rax    # 0x30d508
cmpl $0x4, (%rax)
jne 0x5ab0b
leaq 0x2b2a0f(%rip), %rax    # 0x30d504
cmpl $0x5, (%rax)
jne 0x5ab0b
leaq 0x2b29ff(%rip), %rax    # 0x30d500
cmpl $0x6, (%rax)
jne 0x5ab0b
callq 0xe4dc5
callq 0xa875
leaq 0x2b2c71(%rip), %rax    # 0x30d788
movsd (%rax), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
movsd (%r14), %xmm0
jne 0x5ab3c
jp 0x5ab3c
movsd 0xae53c(%rip), %xmm1    # 0x109070
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
ucomisd %xmm1, %xmm0
leaq 0x2b29b9(%rip), %rbx    # 0x30d500
jbe 0x5ab8d
leaq 0x2b2a50(%rip), %rcx    # 0x30d5a0
movsd (%rcx), %xmm1
ucomisd 0xae54c(%rip), %xmm1    # 0x1090a8
jb 0x5ab8d
cmpl $0x36, (%rbx)
jne 0x5ab8d
addsd 0xae505(%rip), %xmm0    # 0x109070
movsd %xmm0, (%rax)
movl $0x238d, %edi           # imm = 0x238D
callq 0xbe88
leaq 0x1bdcc4(%rip), %rax    # 0x218844
movl $0x238d, (%rax)         # imm = 0x238D
xorl %edi, %edi
callq 0xfc4c8
leaq 0x2b2bfc(%rip), %r15    # 0x30d790
cmpl $0x0, (%r15)
jne 0x5abb3
leaq 0x2b296b(%rip), %rax    # 0x30d50c
movl (%rax), %eax
leaq 0x2b2bd6(%rip), %rcx    # 0x30d780
cmpl (%rcx), %eax
je 0x5abe6
cmpl $0x30, (%rbx)
jne 0x5abe6
leaq 0x2b298e(%rip), %rax    # 0x30d548
movsd (%rax), %xmm0
movl $0xa, %edi
callq 0xe9da0
leaq 0x2b293d(%rip), %rax    # 0x30d50c
movl (%rax), %eax
leaq 0x2b2ba8(%rip), %rcx    # 0x30d780
movl %eax, (%rcx)
movl $0x0, (%r15)
callq 0xf958b
leaq 0x1bdc07(%rip), %rax    # 0x2187f4
movl $0x1, (%rax)
callq 0xe356f
callq 0xe3106
callq 0xe4001
movsd (%r14), %xmm0
callq 0xee139
callq 0x5afd1
callq 0x5b86d
callq 0xf7b6a
callq 0x5a5f5
leaq 0x2b287d(%rip), %r15    # 0x30d4a4
movl (%r15), %eax
leaq 0x2b2877(%rip), %rbx    # 0x30d4a8
cmpl (%rbx), %eax
je 0x5ac3f
callq 0xc3eb7
movl (%r15), %eax
movl %eax, (%rbx)
leaq 0x2b286e(%rip), %rbx    # 0x30d4b4
movl (%rbx), %edx
leaq 0x2b2861(%rip), %r14    # 0x30d4b0
movl (%r14), %ecx
movl %edx, %esi
orl %ecx, %esi
je 0x5ac9d
leaq 0x1e42df(%rip), %rsi    # 0x23ef3e
cmpb $0x0, (%rsi)
je 0x5ac6e
testl %edx, %edx
je 0x5ac82
orl $0x1, %eax
movl %eax, (%r15)
testb $0x1, %al
jne 0x5ac7a
movb $0x3, %al
testl %ecx, %ecx
jne 0x5ac8e
jmp 0x5ac96
testl %edx, %edx
je 0x5ac96
xorl %eax, %eax
jmp 0x5ac8e
testl %ecx, %ecx
je 0x5ac96
andl $-0x2, %eax
movl %eax, (%r15)
movb $0x3, %al
movzbl %al, %edi
callq 0x5b96d
xorl %eax, %eax
movl %eax, (%rbx)
movl %eax, (%r14)
callq 0x5bef0
leaq 0x2b2429(%rip), %rax    # 0x30d0d2
cmpb $0x5, (%rax)
jne 0x5acb3
callq 0xab54
leaq 0x2e061b(%rip), %rax    # 0x33b2d5
cmpb $0x0, (%rax)
je 0x5acd2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b5a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq