// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: parse_sirf_nav()
void parse_sirf_nav()
{
u16 valid;
u16 nav_type;
u32 sats;
u16 secs;
u32 utc_tow;

   log_packet_id("sirf_nav");

   valid = tsip_word();
   nav_type = tsip_word();

   gps_week = tsip_word();
   faked_tow = 0;
   pri_tow = this_tow = tsip_dword();
   pri_tow /= 1000;  // gggg use msecs?

   pri_year = year = tsip_word();
   pri_month = month = tsip_byte();
   pri_day = day = tsip_byte();
   pri_hours = hours = tsip_byte();
   pri_minutes = minutes = tsip_byte();
   secs = tsip_word();

   pri_frac = raw_frac = ((double) (secs % 1000)) / 1000.0;
   pri_seconds = seconds = (secs / 1000);


   if(have_sirf_pps == 0) {  // fake the UTC offset from tow values since some receivers do not do the 52 message
      utc_tow = pri_hours * 24*60*60;
      utc_tow += pri_minutes * 60;
      utc_tow += pri_seconds;
      utc_tow %= 60;

      if(!user_set_utc_ofs) {
         utc_offset = (pri_tow % 60) - utc_tow;
         if(utc_offset < 0) utc_offset += 60;
         utc_offset %= 60;
         check_utc_ofs(4);
      }
//sprintf(plot_title, "utc_tow:%d  tow:%d  delta:%d  valid:%04X  nav:%04X", utc_tow,pri_tow%60, utc_offset, valid,nav_type);
   }

   time_flags |= TFLAGS_UTC;   // UTC based time
   have_timing_mode = 1;
   have_rcvr_tmode = 1;

   if(timing_mode == TMODE_GPS) {  // convert utc time to gps time
      utc_to_gps();
   }

   sats = tsip_dword();
   lat = ((float) (S32) tsip_dword()) * 1.0E-7 * PI / 180.0;
   lon = ((float) (S32) tsip_dword()) * 1.0E-7 * PI / 180.0;
   alt = ((float) (S32) tsip_dword()) * 1.0E-2;

   tsip_dword(); // msl
   tsip_byte();  // datum
   speed = ((double)tsip_word()) / 100.0;    // speed
   heading = ((double) tsip_word()) / 100.0; // course
   tsip_word();  // mag var
   tsip_word();  // climb
   tsip_word();  // heading rate
   tsip_dword(); // horiz err
   tsip_dword(); // vert err
   tsip_dword(); // time err
   tsip_word();  // horiz velocity err
   tsip_dword(); // clock bias
   tsip_dword(); // bias err
   tsip_dword(); // clock drift
   tsip_dword(); // drift err
   tsip_dword(); // distance
   tsip_word();  // distance err
   tsip_word();  // heading err
   tsip_byte();  // sat count
   hdop = ((float) (u08) tsip_byte()) / 5.0F;
   have_dops |= HDOP;
   tsip_byte();  // info

   have_heading = 1;
   have_speed = 1;

   nav_type &= 0x07;
   if((nav_type == 4) || (nav_type == 6)) rcvr_mode = RCVR_MODE_3D;
   else if((nav_type == 3) || (nav_type == 5)) rcvr_mode = RCVR_MODE_2D;
   else rcvr_mode = RCVR_MODE_ACQUIRE;

   if(have_week == 0) need_redraw = 2026;
   have_week = 4;

   if(have_tow == 0) need_redraw = 2027;
   have_tow = 4;

   update_gps_screen(1001);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
leaq 0x8e644(%rip), %rdi     # 0x124888
callq 0x58dc2
callq 0x588d2
callq 0x588d2
movl %eax, %ebx
callq 0x588d2
leaq 0x2774d7(%rip), %rcx    # 0x30d738
movw %ax, (%rcx)
leaq 0x2774dd(%rip), %rax    # 0x30d748
movl $0x0, (%rax)
callq 0x58964
leaq 0x2774c3(%rip), %rcx    # 0x30d740
movl %eax, (%rcx)
movl %eax, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
leaq 0x2774b1(%rip), %r15    # 0x30d744
movl %eax, (%r15)
callq 0x588d2
movzwl %ax, %eax
leaq 0x277237(%rip), %rcx    # 0x30d4dc
movl %eax, (%rcx)
leaq 0x277266(%rip), %r14    # 0x30d514
movl %eax, (%r14)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x962c7
leaq 0x1a8cac(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x277207(%rip), %rcx    # 0x30d4d8
movl %eax, (%rcx)
leaq 0x277236(%rip), %rcx    # 0x30d510
movl %eax, (%rcx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x962f2
leaq 0x1a8c81(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x2771d8(%rip), %rcx    # 0x30d4d4
movl %eax, (%rcx)
leaq 0x277207(%rip), %rcx    # 0x30d50c
movl %eax, (%rcx)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9631d
leaq 0x1a8c56(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x2771a9(%rip), %rcx    # 0x30d4d0
movl %eax, (%rcx)
leaq 0x2771d8(%rip), %r12    # 0x30d508
movl %eax, (%r12)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9634a
leaq 0x1a8c29(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x277178(%rip), %rcx    # 0x30d4cc
movl %eax, (%rcx)
leaq 0x2771a7(%rip), %r13    # 0x30d504
movl %eax, (%r13)
callq 0x588d2
movzwl %ax, %ecx
shrl $0x3, %ecx
imull $0x20c5, %ecx, %ecx     # imm = 0x20C5
shrl $0x14, %ecx
imull $0x3e8, %ecx, %edx      # imm = 0x3E8
subl %edx, %eax
cwtl
cvtsi2sd %eax, %xmm0
divsd 0x72cae(%rip), %xmm0    # 0x109038
leaq 0x27714f(%rip), %rax    # 0x30d4e0
movsd %xmm0, (%rax)
leaq 0x27717c(%rip), %rax    # 0x30d518
movsd %xmm0, (%rax)
leaq 0x277121(%rip), %rax    # 0x30d4c8
movl %ecx, (%rax)
leaq 0x277150(%rip), %rax    # 0x30d500
movl %ecx, (%rax)
leaq 0x276f6b(%rip), %rax    # 0x30d324
leaq 0x277374(%rip), %rdx    # 0x30d734
movl (%rdx), %edx
orl (%rax), %edx
jne 0x96475
imull $0x15180, (%r12), %eax  # imm = 0x15180
imull $0x3c, (%r13), %edx
orl %ecx, %eax
addl %edx, %eax
movl $0x88888889, %ecx       # imm = 0x88888889
movq %rax, %rdx
imulq %rcx, %rdx
shrq $0x25, %rdx
imull $0x3c, %edx, %edx
movl (%r15), %esi
movq %rsi, %rdi
imulq %rcx, %rdi
shrq $0x25, %rdi
imull $0x3c, %edi, %ecx
subl %ecx, %esi
subl %eax, %edx
leal (%rsi,%rdx), %eax
addl $0x3c, %eax
movl %esi, %ecx
addl %edx, %ecx
cmovnsl %ecx, %eax
movsbl %al, %ecx
imull $-0x77, %ecx, %ecx
shrl $0x8, %ecx
addb %al, %cl
movl %ecx, %edx
shrb $0x7, %dl
sarb $0x5, %cl
addb %dl, %cl
movzbl %cl, %ecx
imull $0x3c, %ecx, %ecx
subb %cl, %al
movsbl %al, %ecx
leaq 0x2772f1(%rip), %rdx    # 0x30d728
movl %ecx, (%rdx)
leaq 0x276edc(%rip), %rcx    # 0x30d31c
cmpl $0x0, (%rcx)
jne 0x96475
cmpl $0x7e1, (%r14)          # imm = 0x7E1
setge %dl
cmpb $0x12, %al
setl %sil
andb %dl, %sil
cmpb $0x11, %al
setl %al
orb %sil, %al
jne 0x96475
leaq 0x1823db(%rip), %rax    # 0x218844
movl $0x7d4, (%rax)          # imm = 0x7D4
movl $0x4, (%rcx)
leaq 0x277028(%rip), %r14    # 0x30d4a4
orb $0x1, (%r14)
leaq 0x276f45(%rip), %r15    # 0x30d3cc
movl $0x1, %eax
movl %eax, (%r15)
leaq 0x276f3a(%rip), %rcx    # 0x30d3d0
movl %eax, (%rcx)
leaq 0x27701e(%rip), %rax    # 0x30d4bd
cmpb $0x0, (%rax)
jne 0x964c2
leaq 0x27727d(%rip), %rax    # 0x30d728
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
callq 0x5c7ed
andb $-0x2, (%r14)
movl $0x1, (%r15)
callq 0x58964
callq 0x58964
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x87d79(%rip), %xmm0    # 0x11e258
mulsd 0x75341(%rip), %xmm0    # 0x10b828
divsd 0x75341(%rip), %xmm0    # 0x10b830
leaq 0x276ada(%rip), %rax    # 0x30cfd0
movsd %xmm0, (%rax)
callq 0x58964
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x87d46(%rip), %xmm0    # 0x11e258
mulsd 0x7530e(%rip), %xmm0    # 0x10b828
divsd 0x7530e(%rip), %xmm0    # 0x10b830
leaq 0x276aaf(%rip), %rax    # 0x30cfd8
movsd %xmm0, (%rax)
callq 0x58964
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x72bbb(%rip), %xmm0    # 0x109100
leaq 0x276a94(%rip), %rax    # 0x30cfe0
movsd %xmm0, (%rax)
callq 0x58964
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9656b
leaq 0x1a8a08(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588d2
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x72ade(%rip), %xmm0    # 0x109060
leaq 0x276a97(%rip), %rax    # 0x30d020
movsd %xmm0, (%rax)
callq 0x588d2
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x72abc(%rip), %xmm0    # 0x109060
leaq 0x276a7d(%rip), %rax    # 0x30d028
movsd %xmm0, (%rax)
callq 0x588d2
callq 0x588d2
callq 0x588d2
callq 0x58964
callq 0x58964
callq 0x58964
callq 0x588d2
callq 0x58964
callq 0x58964
callq 0x58964
callq 0x58964
callq 0x58964
callq 0x588d2
callq 0x588d2
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x9660b
leaq 0x1a8968(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x96621
leaq 0x1a8952(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x88429(%rip), %xmm0    # 0x11ea5c
cvtss2sd %xmm0, %xmm0
leaq 0x18ceb2(%rip), %rax    # 0x2234f0
movsd %xmm0, (%rax)
leaq 0x18ce9b(%rip), %rax    # 0x2234e4
orb $0x2, (%rax)
callq 0x587be
cmpl $0x100, %eax            # imm = 0x100
jb 0x96662
leaq 0x1a8911(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x276ccb(%rip), %rax    # 0x30d334
movl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x276cc1(%rip), %rax    # 0x30d338
movl %ecx, (%rax)
movl %ebx, %ecx
andl $0x5, %ecx
movb $0x4, %al
cmpw $0x4, %cx
je 0x9669f
andl $0x7, %ebx
addl $-0x3, %ebx
testl $0xfffd, %ebx           # imm = 0xFFFD
movl $0x3, %ecx
movl $0x9, %eax
cmovel %ecx, %eax
leaq 0x276a2a(%rip), %rcx    # 0x30d0d0
movb %al, (%rcx)
leaq 0x276c7d(%rip), %rax    # 0x30d32c
cmpl $0x0, (%rax)
jne 0x966c1
leaq 0x182189(%rip), %rcx    # 0x218844
movl $0x7ea, (%rcx)          # imm = 0x7EA
movl $0x4, (%rax)
leaq 0x276c5a(%rip), %rax    # 0x30d328
cmpl $0x0, (%rax)
jne 0x966e0
leaq 0x18216a(%rip), %rcx    # 0x218844
movl $0x7eb, (%rcx)          # imm = 0x7EB
movl $0x4, (%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x730e8