// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
leaq 0x85e9f(%rip), %rdi     # 0x10e7d0
callq 0x520bf
callq 0x51c63
callq 0x51c63
movl %eax, %ebx
callq 0x51c63
leaq 0x26edea(%rip), %rcx    # 0x2f7738
movw %ax, (%rcx)
leaq 0x26edf0(%rip), %rax    # 0x2f7748
andl $0x0, (%rax)
callq 0x51cf3
leaq 0x26edd9(%rip), %rcx    # 0x2f7740
movl %eax, (%rcx)
movl $0x3e8, %ecx            # imm = 0x3E8
xorl %edx, %edx
divl %ecx
leaq 0x26edcb(%rip), %r14    # 0x2f7744
movl %eax, (%r14)
callq 0x51c63
movzwl %ax, %eax
leaq 0x26eb51(%rip), %rcx    # 0x2f74dc
movl %eax, (%rcx)
leaq 0x26eb80(%rip), %rcx    # 0x2f7514
movl %eax, (%rcx)
callq 0x51c47
movzbl %al, %eax
leaq 0x26eb33(%rip), %rcx    # 0x2f74d8
movl %eax, (%rcx)
leaq 0x26eb62(%rip), %rcx    # 0x2f7510
movl %eax, (%rcx)
callq 0x51c47
movzbl %al, %eax
leaq 0x26eb15(%rip), %rcx    # 0x2f74d4
movl %eax, (%rcx)
leaq 0x26eb44(%rip), %rcx    # 0x2f750c
movl %eax, (%rcx)
callq 0x51c47
movzbl %al, %eax
leaq 0x26eaf7(%rip), %rcx    # 0x2f74d0
movl %eax, (%rcx)
leaq 0x26eb26(%rip), %r15    # 0x2f7508
movl %eax, (%r15)
callq 0x51c47
movzbl %al, %eax
leaq 0x26ead8(%rip), %rcx    # 0x2f74cc
movl %eax, (%rcx)
leaq 0x26eb07(%rip), %r12    # 0x2f7504
movl %eax, (%r12)
callq 0x51c63
movw $0x3e8, %cx             # imm = 0x3E8
xorl %edx, %edx
divw %cx
movswl %dx, %ecx
cvtsi2sd %ecx, %xmm0
divsd 0x6a61a(%rip), %xmm0    # 0xf3038
leaq 0x26eabb(%rip), %rcx    # 0x2f74e0
movsd %xmm0, (%rcx)
leaq 0x26eae8(%rip), %rcx    # 0x2f7518
movsd %xmm0, (%rcx)
movzwl %ax, %ecx
leaq 0x26ea8a(%rip), %rax    # 0x2f74c8
movl %ecx, (%rax)
leaq 0x26eab9(%rip), %rax    # 0x2f7500
movl %ecx, (%rax)
leaq 0x26e8d4(%rip), %rax    # 0x2f7324
leaq 0x26ecdd(%rip), %rdx    # 0x2f7734
movl (%rdx), %edx
orl (%rax), %edx
jne 0x88aa4
imull $0x15180, (%r15), %eax  # imm = 0x15180
imull $0x3c, (%r12), %edx
orl %ecx, %eax
addl %edx, %eax
pushq $0x3c
popq %rsi
xorl %edx, %edx
divl %esi
movl %edx, %ecx
movl (%r14), %eax
xorl %edx, %edx
divl %esi
subl %ecx, %edx
leal 0x3c(%rdx), %eax
testl %edx, %edx
movzbl %al, %eax
cmovnsl %edx, %eax
cbtw
movb $0x3c, %cl
idivb %cl
movsbl %ah, %eax
leaq 0x26ec8e(%rip), %rcx    # 0x2f7728
movl %eax, (%rcx)
pushq $0x4
popq %rdi
callq 0x51a91
leaq 0x26e9f9(%rip), %rax    # 0x2f74a4
orb $0x1, (%rax)
leaq 0x26e917(%rip), %rax    # 0x2f73cc
pushq $0x1
popq %r14
movl %r14d, (%rax)
leaq 0x26e90d(%rip), %rax    # 0x2f73d0
movl %r14d, (%rax)
leaq 0x26e9f0(%rip), %rax    # 0x2f74bd
cmpb $0x0, (%rax)
jne 0x88ad7
callq 0x554d3
callq 0x51cf3
callq 0x51cf3
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x7f7df(%rip), %xmm0    # 0x1082d0
mulsd 0x6cda7(%rip), %xmm0    # 0xf58a0
divsd 0x6cda7(%rip), %xmm0    # 0xf58a8
leaq 0x26e4c8(%rip), %rax    # 0x2f6fd0
movsd %xmm0, (%rax)
callq 0x51cf3
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x7f7af(%rip), %xmm0    # 0x1082d0
mulsd 0x6cd77(%rip), %xmm0    # 0xf58a0
divsd 0x6cd77(%rip), %xmm0    # 0xf58a8
leaq 0x26e4a0(%rip), %rax    # 0x2f6fd8
movsd %xmm0, (%rax)
callq 0x51cf3
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x6a5af(%rip), %xmm0    # 0xf3100
leaq 0x26e488(%rip), %rax    # 0x2f6fe0
movsd %xmm0, (%rax)
callq 0x51cf3
callq 0x51c47
callq 0x51c63
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
divsd 0x6a4e6(%rip), %xmm0    # 0xf3060
leaq 0x26e49f(%rip), %rax    # 0x2f7020
movsd %xmm0, (%rax)
callq 0x51c63
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
divsd 0x6a4c7(%rip), %xmm0    # 0xf3060
leaq 0x26e488(%rip), %rax    # 0x2f7028
movsd %xmm0, (%rax)
callq 0x51c63
callq 0x51c63
callq 0x51c63
callq 0x51cf3
callq 0x51cf3
callq 0x51cf3
callq 0x51c63
callq 0x51cf3
callq 0x51cf3
callq 0x51cf3
callq 0x51cf3
callq 0x51cf3
callq 0x51c63
callq 0x51c63
callq 0x51c47
callq 0x51c47
movzbl %al, %eax
cvtsi2ss %eax, %xmm0
divss 0x7fdd1(%rip), %xmm0    # 0x1089d4
cvtss2sd %xmm0, %xmm0
leaq 0x1848e2(%rip), %rax    # 0x20d4f0
movsd %xmm0, (%rax)
leaq 0x1848cb(%rip), %rax    # 0x20d4e4
orb $0x2, (%rax)
callq 0x51c47
leaq 0x26e70c(%rip), %rax    # 0x2f7334
movl %r14d, (%rax)
leaq 0x26e706(%rip), %rax    # 0x2f7338
movl %r14d, (%rax)
movl %ebx, %ecx
andl $0x5, %ecx
movb $0x4, %al
cmpw $0x4, %cx
je 0x88c56
andl $0x7, %ebx
addl $-0x3, %ebx
testw $0xfffd, %bx            # imm = 0xFFFD
pushq $0x3
popq %rcx
pushq $0x9
popq %rax
cmovel %ecx, %eax
leaq 0x26e473(%rip), %rcx    # 0x2f70d0
movb %al, (%rcx)
leaq 0x26e6c6(%rip), %rax    # 0x2f732c
cmpl $0x0, (%rax)
jne 0x88c78
leaq 0x179bd2(%rip), %rcx    # 0x202844
movl $0x7ea, (%rcx)          # imm = 0x7EA
movl $0x4, (%rax)
leaq 0x26e6a3(%rip), %rax    # 0x2f7328
cmpl $0x0, (%rax)
jne 0x88c97
leaq 0x179bb3(%rip), %rcx    # 0x202844
movl $0x7eb, (%rcx)          # imm = 0x7EB
movl $0x4, (%rax)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x694f6