// File: /workspace/github_cpp_makefile_star2_O1/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 0x8e67b(%rip), %rdi     # 0x1247a8
callq 0x58e77
callq 0x588f0
callq 0x588f0
movl %eax, %ebx
callq 0x588f0
leaq 0x2775ee(%rip), %rcx    # 0x30d738
movw %ax, (%rcx)
leaq 0x2775f4(%rip), %rax    # 0x30d748
movl $0x0, (%rax)
callq 0x589b0
leaq 0x2775da(%rip), %rcx    # 0x30d740
movl %eax, (%rcx)
movl %eax, %eax
imulq $0x10624dd3, %rax, %rax # imm = 0x10624DD3
shrq $0x26, %rax
leaq 0x2775c8(%rip), %r15    # 0x30d744
movl %eax, (%r15)
callq 0x588f0
movzwl %ax, %eax
leaq 0x27734e(%rip), %rcx    # 0x30d4dc
movl %eax, (%rcx)
leaq 0x27737d(%rip), %r14    # 0x30d514
movl %eax, (%r14)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x961b0
leaq 0x1a8dc3(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x27731e(%rip), %rcx    # 0x30d4d8
movl %eax, (%rcx)
leaq 0x27734d(%rip), %rcx    # 0x30d510
movl %eax, (%rcx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x961db
leaq 0x1a8d98(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x2772ef(%rip), %rcx    # 0x30d4d4
movl %eax, (%rcx)
leaq 0x27731e(%rip), %rcx    # 0x30d50c
movl %eax, (%rcx)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x96206
leaq 0x1a8d6d(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x2772c0(%rip), %rcx    # 0x30d4d0
movl %eax, (%rcx)
leaq 0x2772ef(%rip), %r12    # 0x30d508
movl %eax, (%r12)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x96233
leaq 0x1a8d40(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
leaq 0x27728f(%rip), %rcx    # 0x30d4cc
movl %eax, (%rcx)
leaq 0x2772be(%rip), %r13    # 0x30d504
movl %eax, (%r13)
callq 0x588f0
movzwl %ax, %ecx
imulq $0x418938, %rcx, %rax   # imm = 0x418938
shrq $0x20, %rax
imull $0x3e8, %eax, %edx      # imm = 0x3E8
subl %edx, %ecx
cvtsi2sd %ecx, %xmm0
divsd 0x72dc7(%rip), %xmm0    # 0x109038
leaq 0x277268(%rip), %rcx    # 0x30d4e0
movsd %xmm0, (%rcx)
leaq 0x277295(%rip), %rcx    # 0x30d518
movsd %xmm0, (%rcx)
leaq 0x27723a(%rip), %rcx    # 0x30d4c8
movl %eax, (%rcx)
leaq 0x277269(%rip), %rcx    # 0x30d500
movl %eax, (%rcx)
leaq 0x277084(%rip), %rcx    # 0x30d324
leaq 0x27748d(%rip), %rdx    # 0x30d734
movl (%rdx), %edx
orl (%rcx), %edx
jne 0x9635c
imull $0x15180, (%r12), %ecx  # imm = 0x15180
imull $0x3c, (%r13), %edx
orl %eax, %ecx
addl %edx, %ecx
movl $0x88888889, %eax       # imm = 0x88888889
movq %rcx, %rdx
imulq %rax, %rdx
shrq $0x25, %rdx
imull $0x3c, %edx, %edx
movl (%r15), %esi
movq %rsi, %rdi
imulq %rax, %rdi
shrq $0x25, %rdi
imull $0x3c, %edi, %eax
subl %eax, %esi
subl %ecx, %edx
leal (%rsi,%rdx), %eax
addl $0x3c, %eax
movl %esi, %ecx
addl %edx, %ecx
cmovnsl %ecx, %eax
cltq
imulq $-0x77777777, %rax, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x5, %ecx
addl %edx, %ecx
imull $0x3c, %ecx, %ecx
subl %ecx, %eax
leaq 0x27740c(%rip), %rcx    # 0x30d728
movl %eax, (%rcx)
leaq 0x276ff7(%rip), %rcx    # 0x30d31c
cmpl $0x0, (%rcx)
jne 0x9635c
cmpl $0x7e1, (%r14)          # imm = 0x7E1
setge %dl
cmpl $0x12, %eax
setl %sil
andb %dl, %sil
cmpl $0x11, %eax
setl %al
orb %sil, %al
jne 0x9635c
leaq 0x1824f4(%rip), %rax    # 0x218844
movl $0x7d4, (%rax)          # imm = 0x7D4
movl $0x4, (%rcx)
leaq 0x277141(%rip), %r14    # 0x30d4a4
orb $0x1, (%r14)
leaq 0x27705e(%rip), %r15    # 0x30d3cc
movl $0x1, %eax
movl %eax, (%r15)
leaq 0x277053(%rip), %rcx    # 0x30d3d0
movl %eax, (%rcx)
leaq 0x277137(%rip), %rax    # 0x30d4bd
cmpb $0x0, (%rax)
jne 0x963a9
leaq 0x277396(%rip), %rax    # 0x30d728
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
callq 0x5c907
andb $-0x2, (%r14)
movl $0x1, (%r15)
callq 0x589b0
callq 0x589b0
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x87dea(%rip), %xmm0    # 0x11e1b0
mulsd 0x7544a(%rip), %xmm0    # 0x10b818
divsd 0x7544a(%rip), %xmm0    # 0x10b820
leaq 0x276bf3(%rip), %rax    # 0x30cfd0
movsd %xmm0, (%rax)
callq 0x589b0
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x87db7(%rip), %xmm0    # 0x11e1b0
mulsd 0x75417(%rip), %xmm0    # 0x10b818
divsd 0x75417(%rip), %xmm0    # 0x10b820
leaq 0x276bc8(%rip), %rax    # 0x30cfd8
movsd %xmm0, (%rax)
callq 0x589b0
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x72cd4(%rip), %xmm0    # 0x109100
leaq 0x276bad(%rip), %rax    # 0x30cfe0
movsd %xmm0, (%rax)
callq 0x589b0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x96452
leaq 0x1a8b21(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x588f0
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x72bf7(%rip), %xmm0    # 0x109060
leaq 0x276bb0(%rip), %rax    # 0x30d020
movsd %xmm0, (%rax)
callq 0x588f0
movzwl %ax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x72bd5(%rip), %xmm0    # 0x109060
leaq 0x276b96(%rip), %rax    # 0x30d028
movsd %xmm0, (%rax)
callq 0x588f0
callq 0x588f0
callq 0x588f0
callq 0x589b0
callq 0x589b0
callq 0x589b0
callq 0x588f0
callq 0x589b0
callq 0x589b0
callq 0x589b0
callq 0x589b0
callq 0x589b0
callq 0x588f0
callq 0x588f0
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x964f2
leaq 0x1a8a81(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x96508
leaq 0x1a8a6b(%rip), %rcx    # 0x23ef70
orb $0x8, (%rcx)
movzbl %al, %eax
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x88492(%rip), %xmm0    # 0x11e9ac
cvtss2sd %xmm0, %xmm0
leaq 0x18cfcb(%rip), %rax    # 0x2234f0
movsd %xmm0, (%rax)
leaq 0x18cfb4(%rip), %rax    # 0x2234e4
orb $0x2, (%rax)
callq 0x587d1
cmpl $0x100, %eax            # imm = 0x100
jb 0x96549
leaq 0x1a8a2a(%rip), %rax    # 0x23ef70
orb $0x8, (%rax)
leaq 0x276de4(%rip), %rax    # 0x30d334
movl $0x1, %ecx
movl %ecx, (%rax)
leaq 0x276dda(%rip), %rax    # 0x30d338
movl %ecx, (%rax)
movl %ebx, %ecx
andl $0x5, %ecx
movb $0x4, %al
cmpw $0x4, %cx
je 0x96586
andl $0x7, %ebx
addl $-0x3, %ebx
testl $0xfffd, %ebx           # imm = 0xFFFD
movl $0x3, %ecx
movl $0x9, %eax
cmovel %ecx, %eax
leaq 0x276b43(%rip), %rcx    # 0x30d0d0
movb %al, (%rcx)
leaq 0x276d96(%rip), %rax    # 0x30d32c
cmpl $0x0, (%rax)
jne 0x965a8
leaq 0x1822a2(%rip), %rcx    # 0x218844
movl $0x7ea, (%rcx)          # imm = 0x7EA
movl $0x4, (%rax)
leaq 0x276d73(%rip), %rax    # 0x30d328
cmpl $0x0, (%rax)
jne 0x965c7
leaq 0x182283(%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 0x7327e