// File: 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
subq $0x30, %rsp
leaq 0xbaf85(%rip), %rdi     # 0x187b74
callq 0x7add0
callq 0x7a560
movw %ax, -0x2(%rbp)
callq 0x7a560
movw %ax, -0x4(%rbp)
callq 0x7a560
movw %ax, %cx
leaq 0x29fd03(%rip), %rax    # 0x36c918
movw %cx, (%rax)
leaq 0x29fd09(%rip), %rax    # 0x36c928
movl $0x0, (%rax)
callq 0x7a680
movl %eax, %ecx
leaq 0x29fced(%rip), %rax    # 0x36c920
movl %ecx, (%rax)
leaq 0x29fce8(%rip), %rax    # 0x36c924
movl %ecx, (%rax)
leaq 0x29fcdf(%rip), %rax    # 0x36c924
movl (%rax), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
leaq 0x29fccb(%rip), %rax    # 0x36c924
movl %ecx, (%rax)
callq 0x7a560
movzwl %ax, %ecx
leaq 0x29fa52(%rip), %rax    # 0x36c6bc
movl %ecx, (%rax)
leaq 0x29fa81(%rip), %rax    # 0x36c6f4
movl %ecx, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x29fa34(%rip), %rax    # 0x36c6b8
movl %ecx, (%rax)
leaq 0x29fa63(%rip), %rax    # 0x36c6f0
movl %ecx, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x29fa16(%rip), %rax    # 0x36c6b4
movl %ecx, (%rax)
leaq 0x29fa45(%rip), %rax    # 0x36c6ec
movl %ecx, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x29f9f8(%rip), %rax    # 0x36c6b0
movl %ecx, (%rax)
leaq 0x29fa27(%rip), %rax    # 0x36c6e8
movl %ecx, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x29f9da(%rip), %rax    # 0x36c6ac
movl %ecx, (%rax)
leaq 0x29fa09(%rip), %rax    # 0x36c6e4
movl %ecx, (%rax)
callq 0x7a560
movw %ax, -0xa(%rbp)
movzwl -0xa(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
cvtsi2sd %edx, %xmm0
movsd 0xa2332(%rip), %xmm1    # 0x16f030
divsd %xmm1, %xmm0
leaq 0x29f9b7(%rip), %rax    # 0x36c6c0
movsd %xmm0, (%rax)
leaq 0x29f9e4(%rip), %rax    # 0x36c6f8
movsd %xmm0, (%rax)
movzwl -0xa(%rbp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
movl %eax, %ecx
leaq 0x29f97b(%rip), %rax    # 0x36c6a8
movl %ecx, (%rax)
leaq 0x29f9aa(%rip), %rax    # 0x36c6e0
movl %ecx, (%rax)
leaq 0x29f7c5(%rip), %rax    # 0x36c504
cmpl $0x0, (%rax)
jne 0xccdfa
leaq 0x29f999(%rip), %rax    # 0x36c6e8
imull $0x18, (%rax), %eax
imull $0x3c, %eax, %eax
imull $0x3c, %eax, %eax
movl %eax, -0x10(%rbp)
leaq 0x29f982(%rip), %rax    # 0x36c6e4
imull $0x3c, (%rax), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
leaq 0x29f96e(%rip), %rax    # 0x36c6e0
movl (%rax), %eax
addl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
movl $0x3c, %ecx
xorl %edx, %edx
divl %ecx
movl %edx, -0x10(%rbp)
leaq 0x29fb84(%rip), %rax    # 0x36c914
cmpl $0x0, (%rax)
jne 0xccdf8
leaq 0x29fb88(%rip), %rax    # 0x36c924
movl (%rax), %eax
movl $0x3c, %ecx
xorl %edx, %edx
divl %ecx
subl -0x10(%rbp), %edx
leaq 0x29fb57(%rip), %rax    # 0x36c908
movl %edx, (%rax)
leaq 0x29fb4e(%rip), %rax    # 0x36c908
cmpl $0x0, (%rax)
jge 0xccdd4
leaq 0x29fb42(%rip), %rax    # 0x36c908
movl (%rax), %ecx
addl $0x3c, %ecx
leaq 0x29fb36(%rip), %rax    # 0x36c908
movl %ecx, (%rax)
leaq 0x29fb2d(%rip), %rax    # 0x36c908
movl (%rax), %eax
movl $0x3c, %ecx
cltd
idivl %ecx
leaq 0x29fb1c(%rip), %rax    # 0x36c908
movl %edx, (%rax)
movl $0x4, %edi
callq 0x7a270
jmp 0xccdfa
leaq 0x29f883(%rip), %rax    # 0x36c684
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x29f877(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
leaq 0x29f796(%rip), %rax    # 0x36c5ac
movl $0x1, (%rax)
leaq 0x29f78d(%rip), %rax    # 0x36c5b0
movl $0x1, (%rax)
leaq 0x29f86d(%rip), %rax    # 0x36c69d
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xcce3d
callq 0x7fc70
callq 0x7a680
movl %eax, -0x8(%rbp)
callq 0x7a680
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xa234e(%rip), %xmm1    # 0x16f1a8
movsd %xmm1, -0x30(%rbp)
mulsd %xmm1, %xmm0
movsd 0xa475d(%rip), %xmm1    # 0x1715c8
movsd %xmm1, -0x28(%rbp)
mulsd %xmm1, %xmm0
movsd 0xa21fc(%rip), %xmm1    # 0x16f078
movsd %xmm1, -0x20(%rbp)
divsd %xmm1, %xmm0
leaq 0x29f324(%rip), %rax    # 0x36c1b0
movsd %xmm0, (%rax)
callq 0x7a680
movsd -0x30(%rbp), %xmm3
movsd -0x28(%rbp), %xmm2
movsd -0x20(%rbp), %xmm1
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
divsd %xmm1, %xmm0
leaq 0x29f2f9(%rip), %rax    # 0x36c1b8
movsd %xmm0, (%rax)
callq 0x7a680
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0xa2248(%rip), %xmm1    # 0x16f120
mulsd %xmm1, %xmm0
leaq 0x29f2dd(%rip), %rax    # 0x36c1c0
movsd %xmm0, (%rax)
callq 0x7a680
callq 0x7a510
callq 0x7a560
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
movsd 0xa214b(%rip), %xmm1    # 0x16f050
movsd %xmm1, -0x18(%rbp)
divsd %xmm1, %xmm0
leaq 0x29f2eb(%rip), %rax    # 0x36c200
movsd %xmm0, (%rax)
callq 0x7a560
movsd -0x18(%rbp), %xmm1
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
leaq 0x29f2d3(%rip), %rax    # 0x36c208
movsd %xmm0, (%rax)
callq 0x7a560
callq 0x7a560
callq 0x7a560
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a560
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a560
callq 0x7a560
callq 0x7a510
callq 0x7a510
movzbl %al, %eax
cvtsi2ss %eax, %xmm0
movss 0xb63cc(%rip), %xmm1    # 0x183364
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1b5729(%rip), %rax    # 0x2826d0
movsd %xmm0, (%rax)
leaq 0x1b5712(%rip), %rax    # 0x2826c4
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x1b5706(%rip), %rax    # 0x2826c4
movl %ecx, (%rax)
callq 0x7a510
leaq 0x29f548(%rip), %rax    # 0x36c514
movl $0x1, (%rax)
leaq 0x29f53f(%rip), %rax    # 0x36c518
movl $0x1, (%rax)
movzwl -0x4(%rbp), %eax
andl $0x7, %eax
movw %ax, -0x4(%rbp)
movzwl -0x4(%rbp), %eax
cmpl $0x4, %eax
je 0xccffc
movzwl -0x4(%rbp), %eax
cmpl $0x6, %eax
jne 0xcd008
leaq 0x29f2ad(%rip), %rax    # 0x36c2b0
movb $0x4, (%rax)
jmp 0xcd032
movzwl -0x4(%rbp), %eax
cmpl $0x3, %eax
je 0xcd01a
movzwl -0x4(%rbp), %eax
cmpl $0x5, %eax
jne 0xcd026
leaq 0x29f28f(%rip), %rax    # 0x36c2b0
movb $0x3, (%rax)
jmp 0xcd030
leaq 0x29f283(%rip), %rax    # 0x36c2b0
movb $0x9, (%rax)
jmp 0xcd032
leaq 0x29f4d3(%rip), %rax    # 0x36c50c
cmpl $0x0, (%rax)
jne 0xcd04b
leaq 0x1aa9df(%rip), %rax    # 0x277a24
movl $0x7ea, (%rax)          # imm = 0x7EA
leaq 0x29f4ba(%rip), %rax    # 0x36c50c
movl $0x4, (%rax)
leaq 0x29f4a9(%rip), %rax    # 0x36c508
cmpl $0x0, (%rax)
jne 0xcd071
leaq 0x1aa9b9(%rip), %rax    # 0x277a24
movl $0x7eb, (%rax)          # imm = 0x7EB
leaq 0x29f490(%rip), %rax    # 0x36c508
movl $0x4, (%rax)
movl $0x3e9, %edi            # imm = 0x3E9
callq 0x9d790
addq $0x30, %rsp
popq %rbp
retq
nop