// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b2d1c(%rip), %rax    # 0x30d4c8
movl (%rax), %eax
movl %eax, 0x10fbbc(%rip)    # 0x16a370
leaq 0x2b2ce9(%rip), %rax    # 0x30d4a4
testb $0x1, (%rax)
jne 0x5a7eb
leaq 0x2b2f61(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd41e0
leaq 0x2b2d53(%rip), %rax    # 0x30d530
movsd (%rax), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax)
jmp 0x5a821
leaq 0x2b2d3e(%rip), %rax    # 0x30d530
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2b2f26(%rip), %rax    # 0x30d728
movl (%rax), %edx
xorpd %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
callq 0xd41e0
addsd -0x30(%rbp), %xmm0
leaq 0x2b2d1b(%rip), %rax    # 0x30d538
movsd %xmm0, (%rax)
leaq 0x2b2d10(%rip), %rax    # 0x30d538
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xcdcec
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq 0x2b2ee1(%rip), %rax    # 0x30d728
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
leaq 0x2b3673(%rip), %r13    # 0x30dec8
movsd (%r13), %xmm0
divsd 0xae7d5(%rip), %xmm0    # 0x109038
addsd %xmm1, %xmm0
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
leaq 0x2b2cbe(%rip), %r12    # 0x30d540
movsd %xmm1, (%r12)
leaq 0x2b2ca1(%rip), %r14    # 0x30d530
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xe0c30
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0xae782(%rip), %xmm0    # 0x109038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x30(%rbp), %xmm0
leaq 0x2b2c7b(%rip), %rax    # 0x30d548
movsd %xmm0, (%rax)
xorl %edi, %edi
callq 0xd0c46
leaq 0x2b2dc5(%rip), %rax    # 0x30d6a4
movl (%rax), %edi
leaq 0x2b2c38(%rip), %rbx    # 0x30d520
movl %edi, (%rbx)
leaq 0x1e45eb(%rip), %rax    # 0x23eedc
movb $0x1, (%rax)
leaq 0x1e45e5(%rip), %rax    # 0x23eee0
leaq 0x2b2bda(%rip), %rcx    # 0x30d4dc
movl (%rcx), %ecx
cmpl %ecx, (%rax)
je 0x5a94c
movl %ecx, (%rax)
callq 0xdfc78
movl (%rbx), %edi
leaq 0x2b2f84(%rip), %r15    # 0x30d89c
movslq (%r15), %rax
movq %r14, %r13
movq %r12, %r14
leaq 0x10ff08(%rip), %r12    # 0x16a830
movq (%r12,%rax,8), %rsi
callq 0xe0868
movl (%rbx), %edi
movslq (%r15), %rax
movq (%r12,%rax,8), %rsi
movq %r14, %r12
movq %r13, %r14
leaq 0x2b3581(%rip), %r13    # 0x30dec8
callq 0xe0868
leaq 0x2b358d(%rip), %rax    # 0x30dee0
xorb $0x1, (%rax)
movl $0xa, %edi
callq 0xe1b3f
leaq 0x2b2b69(%rip), %rbx    # 0x30d4d0
movl (%rbx), %eax
leaq 0x2b2d90(%rip), %r15    # 0x30d700
cmpl (%r15), %eax
je 0x5a9ca
callq 0xe0af6
leaq 0x2b2f1f(%rip), %rcx    # 0x30d8a0
movl %eax, (%rcx)
movsd (%r14), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xe0c30
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd (%r13), %xmm0
divsd 0xae68e(%rip), %xmm0    # 0x109038
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0xd41e0
addsd -0x30(%rbp), %xmm0
leaq 0x2b2b87(%rip), %rax    # 0x30d548
movsd %xmm0, (%rax)
movl (%rbx), %eax
movl %eax, (%r15)
leaq 0x2b2df7(%rip), %rbx    # 0x30d7c8
xorl %eax, %eax
movl %eax, (%rbx)
leaq 0x2b2e34(%rip), %rcx    # 0x30d810
movl %eax, (%rcx)
leaq 0x2b25eb(%rip), %r15    # 0x30cfd0
movsd (%r15), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
leaq 0x2b25df(%rip), %r13    # 0x30cfd8
jne 0x5aa0b
jp 0x5aa0b
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5aa0b
jnp 0x5aa6d
movsd (%r14), %xmm0
xorl %edi, %edi
callq 0xe77bd
leaq 0x2b2db2(%rip), %rax    # 0x30d7d0
cvtsd2ss (%rax), %xmm2
leaq 0x2b2d8f(%rip), %rax    # 0x30d7b8
movsd %xmm0, (%rax)
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movl $0x3e8, %edi            # imm = 0x3E8
movaps %xmm2, %xmm0
callq 0x5ad98
movl $0x1, (%rbx)
callq 0xf49ab
movsd (%r12), %xmm0
callq 0xe6724
leaq 0x1c0982(%rip), %rax    # 0x21b3e0
movb (%rax), %cl
testb %cl, %cl
je 0x5aa68
decb %cl
movb %cl, (%rax)
callq 0x5af2f
leaq 0x2b2b40(%rip), %rax    # 0x30d5b4
leaq 0x2b2b35(%rip), %r12    # 0x30d5b0
movl (%r12), %ecx
orl (%rax), %ecx
jne 0x5aaa3
leaq 0x2b2a7a(%rip), %rax    # 0x30d504
cmpl $0x0, (%rax)
jne 0x5ab40
leaq 0x2b2a66(%rip), %rax    # 0x30d500
cmpl $0x1a, (%rax)
jne 0x5ab40
leaq 0x2b2872(%rip), %rax    # 0x30d31c
cmpl $0x0, (%rax)
je 0x5ab40
leaq 0x2b2bc6(%rip), %rax    # 0x30d680
cmpl $0x0, (%rax)
je 0x5aac6
callq 0xe82a0
jmp 0x5aad4
xorpd %xmm0, %xmm0
movl $0x14, %edi
callq 0xe8764
movsd (%r15), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x5ab38
jp 0x5ab38
movsd (%r13), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5ab38
jp 0x5ab38
leaq 0x1bddd6(%rip), %rax    # 0x2188d0
movq (%rax), %rax
movabsq $0x105b8b0400, %rcx     # imm = 0x105B8B0400
testq %rcx, %rax
jne 0x5ab38
leaq 0x1c04bd(%rip), %rcx    # 0x21afd0
cmpl $0x0, (%rcx)
je 0x5ab24
leaq 0x2b28a5(%rip), %rcx    # 0x30d3c4
cmpl $0x0, (%rcx)
je 0x5ab38
cmpq $0x400000, %rax         # imm = 0x400000
jne 0x5ab40
leaq 0x2b2e81(%rip), %rax    # 0x30d9b4
cmpl $0x0, (%rax)
jne 0x5ab40
movl $0x0, (%r12)
movsd (%r14), %xmm0
callq 0xe5f56
callq 0xf4430
leaq 0x2b335e(%rip), %rax    # 0x30deb4
cmpb $0x0, (%rax)
je 0x5ab70
leaq 0x2b299e(%rip), %rax    # 0x30d500
cmpl $0x6, (%rax)
leaq 0x2b2938(%rip), %r12    # 0x30d4a4
je 0x5abb3
jmp 0x5abb8
leaq 0x2b333c(%rip), %rax    # 0x30deb3
cmpb $0x0, (%rax)
leaq 0x2b2923(%rip), %r12    # 0x30d4a4
jne 0x5ab9b
leaq 0x2b3328(%rip), %rax    # 0x30deb2
cmpb $0x0, (%rax)
je 0x5abb8
leaq 0x2b2972(%rip), %rax    # 0x30d508
cmpl $0x4, (%rax)
jne 0x5abb8
leaq 0x2b2962(%rip), %rax    # 0x30d504
cmpl $0x5, (%rax)
jne 0x5abb8
leaq 0x2b2952(%rip), %rax    # 0x30d500
cmpl $0x6, (%rax)
jne 0x5abb8
callq 0xe41cc
callq 0xa886
leaq 0x2b2bc4(%rip), %rax    # 0x30d788
movsd (%rax), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x5abe5
jp 0x5abe5
movsd (%r14), %xmm0
addsd 0xae48f(%rip), %xmm0    # 0x109070
movsd %xmm0, (%rax)
movsd (%r14), %xmm0
ucomisd (%rax), %xmm0
leaq 0x2b290b(%rip), %r15    # 0x30d500
jbe 0x5ac3c
leaq 0x2b29a2(%rip), %rcx    # 0x30d5a0
movsd (%rcx), %xmm1
ucomisd 0xae49e(%rip), %xmm1    # 0x1090a8
jb 0x5ac3c
cmpl $0x36, (%r15)
jne 0x5ac3c
addsd 0xae456(%rip), %xmm0    # 0x109070
movsd %xmm0, (%rax)
movl $0x238d, %edi           # imm = 0x238D
callq 0xbe9d
leaq 0x1bdc15(%rip), %rax    # 0x218844
movl $0x238d, (%rax)         # imm = 0x238D
xorl %edi, %edi
callq 0xfbd5d
leaq 0x2b2b4d(%rip), %rbx    # 0x30d790
movl (%rbx), %eax
testl %eax, %eax
jne 0x5ac5d
leaq 0x2b28bc(%rip), %rcx    # 0x30d50c
movl (%rcx), %ecx
leaq 0x2b2b27(%rip), %rdx    # 0x30d780
cmpl (%rdx), %ecx
je 0x5ac99
testl %eax, %eax
jne 0x5ac67
cmpl $0x30, (%r15)
jne 0x5ac99
leaq 0x2b28da(%rip), %rax    # 0x30d548
movsd (%rax), %xmm0
movl $0xa, %edi
callq 0xe932d
leaq 0x2b2889(%rip), %rax    # 0x30d50c
movl (%rax), %eax
leaq 0x2b2af4(%rip), %rcx    # 0x30d780
movl %eax, (%rcx)
movl $0x0, (%rbx)
callq 0xf8e5e
leaq 0x1bdb54(%rip), %rax    # 0x2187f4
movl $0x1, (%rax)
callq 0xe2a16
callq 0xe25b7
callq 0xe3401
movsd (%r14), %xmm0
callq 0xedaf5
callq 0x5b097
callq 0x5b954
callq 0xf7486
callq 0x5a69a
movl (%r12), %eax
leaq 0x2b27ca(%rip), %rbx    # 0x30d4a8
cmpl (%rbx), %eax
je 0x5aced
callq 0xc3884
movl (%r12), %eax
movl %eax, (%rbx)
leaq 0x2b27c0(%rip), %r14    # 0x30d4b4
movl (%r14), %eax
leaq 0x2b27b2(%rip), %r15    # 0x30d4b0
movl (%r15), %ecx
movl %eax, %edx
orl %ecx, %edx
je 0x5ad54
leaq 0x1e4230(%rip), %rdx    # 0x23ef3e
cmpb $0x0, (%rdx)
je 0x5ad2f
testl %eax, %eax
je 0x5ad20
movl (%r12), %edx
orl $0x1, %edx
jmp 0x5ad2b
testl %ecx, %ecx
je 0x5ad2f
movl (%r12), %edx
andl $-0x2, %edx
movl %edx, (%r12)
testb $0x1, (%r12)
jne 0x5ad3e
movb $0x3, %al
testl %ecx, %ecx
jne 0x5ad44
jmp 0x5ad4c
testl %eax, %eax
je 0x5ad4c
xorl %eax, %eax
movzbl %al, %edi
callq 0x5ba54
xorl %eax, %eax
movl %eax, (%r14)
movl %eax, (%r15)
callq 0x5c009
leaq 0x2b2372(%rip), %rax    # 0x30d0d2
cmpb $0x5, (%rax)
jne 0x5ad6a
callq 0xab5f
leaq 0x2e0564(%rip), %rax    # 0x33b2d5
cmpb $0x0, (%rax)
je 0x5ad89
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3b52b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq