// File: jkingan[P]ladyheather/heathgps.cpp
// Function: parse_moto_Ha(int)
void parse_moto_Ha(int long_msg)
{
int i;
int prn;
int mode;
int sig;
int iode;
int status;
int r_status;
int dop;
int bias;
u16 tword;
S32 ofs;
int utc;
int acc;
float t;
S32 frac;

//max_sats = 12;
//ebolt = 1;
   log_packet_id("position/satellite info");
   if(moto_chans != 12) {
      moto_chans = 12;
      config_msg_ofs();
   }

   get_moto_time(1);
   frac = (S32) tsip_dword();  // !!!! fractional time in nsec 
   pri_frac = raw_frac = ((double) frac) / 1.0E9;

   get_moto_lla();
   tsip_dword();  // msl altitude

   if(long_msg) {
      tsip_dword();  // unfiltered posn
      tsip_dword();
      tsip_dword();
      tsip_dword();  // msl altitude
   }

   speed = ((double) tsip_word()) / 100.0;   // 3d speed
   tsip_word();                              // 2d speed
   heading = ((double) tsip_word()) / 10.0;  // heading

   have_heading = 2;
   have_speed = 2;

   dop = tsip_word();
   have_dops = 0;

   sat_count = tsip_byte();    // visible
   track_count = tsip_byte();  // tracked
   have_count = 6;

   if(long_msg) {
      reset_sat_tracking();
      sat_count = 0;
      for(i=0; i<12; i++) {
         prn = tsip_byte();
         mode = tsip_byte();
         sig = tsip_byte();
         iode = tsip_byte();
         status = tsip_word();
         if((prn >= 1) && (prn <= MAX_PRN)) { 
            if(0 && (sig >= 2)) sat[prn].sig_level = (float) (20.0*log10((double) sig)+6.00);
            else sat[prn].sig_level = ((float) sig);

            sat[prn].level_msg = 13;

            sat[prn].state = mode;
            sat[prn].iode = (u08) iode;

            have_snr |= rinex_gnss(prn);

            acc = (status & 0x000F);
            sat[prn].sv_accuracy = ura_to_dist(prn, acc);

            if(have_state == 0) need_redraw = 2044;
            have_state = MOTO_STATE;  // STATE

            if(have_accu == 0) need_redraw = 2045;
            have_accu = 1;

            sat[prn].tracking = (-1);
            if(status & 0x0880) {
               if(0 || (mode == 8)) {
                  sat[prn].tracking = 1;
               }
            }

            record_sig_levels(prn);
            ++sat_count;
            have_count = 23;
         }
      }
      config_sat_count(sat_count);
   }

   r_status = get_moto_status();

   have_dops = 0;
   if((r_status & 0xE000) == 0xE000) {
      pdop = ((float) dop) / 10.0F;  // 3D fix
      have_dops |= PDOP;
   }
   else if((r_status & 0xE000) == 0x6000) {
      hdop = ((float) dop) / 10.0F;  // 2D fix
      have_dops |= HDOP;
   }
   else {
      hdop = pdop = ((float) dop) / 10.0F;  // 2D fix
      have_dops |= (HDOP | PDOP);  // !!!!
   }

   tsip_word();  // reserved

   if(long_msg) {
      bias = (int) (s16) tsip_word();  // nanoseconds
      ofs = tsip_dword();
      osc_offset = bias;  // !!!! zzzzz
      have_osc_offset = 6;
      have_rcvr_osc = 6;
//adadad      if(jitter_adev == 0) do_osc_adev(osc_offset);

      tword = tsip_word();  // temperature
      t = ((float) (s16) tword) / 2.0F;  // temperature
//sprintf(debug_text2, "tword:%d %04X  t=%g", tword,tword,t);
      if(have_temperature || (t != 0.0)) {
         temperature = t;
         have_temperature = 108;
      }

      utc = tsip_byte();  // time mode 
      if(utc & 0x80) time_flags |= TFLAGS_UTC;     // utc time
      else           time_flags &= (~TFLAGS_UTC);  // gps time

      if(utc & 0x40) time_flags &= (~TFLAGS_NO_UTC_OFS);  // utc offset avail
      else           time_flags |= (TFLAGS_NO_UTC_OFS);

      if(!user_set_utc_ofs) {
         utc_offset = utc & 0x1F;
         check_utc_ofs(9);
      }

      get_moto_tz();
   }

   get_moto_tag();

//sprintf(plot_title, "r_status:%04X  bias:%d  ofs:%d  t:%f  utc:%02X  tag:%s  tmode:%d thresh:%d", 
//r_status, bias, ofs, t, utc, id_tag, traim_mode,traim_threshold);

   level_type = "dBc"; 

   update_gps_screen(1005);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
leaq 0xb4591(%rip), %rdi     # 0x188143
callq 0x7add0
leaq 0x1a6646(%rip), %rax    # 0x27a204
cmpl $0xc, (%rax)
je 0xd3bd5
leaq 0x1a663a(%rip), %rax    # 0x27a204
movl $0xc, (%rax)
callq 0x63c20
movl $0x1, %edi
callq 0xd1ba0
callq 0x7a680
movl %eax, -0x40(%rbp)
cvtsi2sdl -0x40(%rbp), %xmm0
movsd 0x9b434(%rip), %xmm1    # 0x16f028
divsd %xmm1, %xmm0
leaq 0x298ac1(%rip), %rax    # 0x36c6c0
movsd %xmm0, (%rax)
leaq 0x298aee(%rip), %rax    # 0x36c6f8
movsd %xmm0, (%rax)
callq 0xd1ac0
callq 0x7a680
cmpl $0x0, -0x4(%rbp)
je 0xd3c32
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a680
callq 0x7a560
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
movsd 0x9b40a(%rip), %xmm1    # 0x16f050
divsd %xmm1, %xmm0
leaq 0x2985af(%rip), %rax    # 0x36c200
movsd %xmm0, (%rax)
callq 0x7a560
callq 0x7a560
movzwl %ax, %eax
cvtsi2sd %eax, %xmm0
movsd 0x9b452(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
leaq 0x29858f(%rip), %rax    # 0x36c208
movsd %xmm0, (%rax)
leaq 0x298890(%rip), %rax    # 0x36c514
movl $0x2, (%rax)
leaq 0x298887(%rip), %rax    # 0x36c518
movl $0x2, (%rax)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0x24(%rbp)
leaq 0x1aea1b(%rip), %rax    # 0x2826c4
movl $0x0, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x1ca42e(%rip), %rax    # 0x29e0ec
movl %ecx, (%rax)
callq 0x7a510
movzbl %al, %ecx
leaq 0x1ca411(%rip), %rax    # 0x29e0e0
movl %ecx, (%rax)
leaq 0x298820(%rip), %rax    # 0x36c4f8
movl $0x6, (%rax)
cmpl $0x0, -0x4(%rbp)
je 0xd3f03
callq 0x81c10
leaq 0x1ca3f8(%rip), %rax    # 0x29e0ec
movl $0x0, (%rax)
movl $0x0, -0x8(%rbp)
cmpl $0xc, -0x8(%rbp)
jge 0xd3ef5
callq 0x7a510
movzbl %al, %eax
movl %eax, -0xc(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x10(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x14(%rbp)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x18(%rbp)
callq 0x7a560
movzwl %ax, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x1, -0xc(%rbp)
jl 0xd3ee5
cmpl $0x3e7, -0xc(%rbp)      # imm = 0x3E7
jg 0xd3ee5
cvtsi2ssl -0x14(%rbp), %xmm0
movslq -0xc(%rbp), %rcx
leaq 0x1ca427(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss %xmm0, 0x20(%rax)
movslq -0xc(%rbp), %rcx
leaq 0x1ca40d(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0xd, 0x1c(%rax)
movl -0x10(%rbp), %ecx
movslq -0xc(%rbp), %rdx
leaq 0x1ca3ee(%rip), %rax    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rax
movl %ecx, 0x18(%rax)
movl -0x18(%rbp), %eax
movb %al, %cl
movslq -0xc(%rbp), %rdx
leaq 0x1ca3d1(%rip), %rax    # 0x29e190
imulq $0x348, %rdx, %rdx      # imm = 0x348
addq %rdx, %rax
movb %cl, 0x1f1(%rax)
movl -0xc(%rbp), %edi
callq 0x12d280
movl %eax, %ecx
leaq 0x29874c(%rip), %rax    # 0x36c52c
orl (%rax), %ecx
leaq 0x298743(%rip), %rax    # 0x36c52c
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
andl $0xf, %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %edi
movl -0x38(%rbp), %esi
callq 0xb3220
movslq -0xc(%rbp), %rcx
leaq 0x1ca386(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movss %xmm0, 0x1fc(%rax)
leaq 0x2986f9(%rip), %rax    # 0x36c51c
cmpl $0x0, (%rax)
jne 0xd3e35
leaq 0x1a3bf5(%rip), %rax    # 0x277a24
movl $0x7fc, (%rax)          # imm = 0x7FC
leaq 0x2986e0(%rip), %rax    # 0x36c51c
movl $0x2, (%rax)
leaq 0x298757(%rip), %rax    # 0x36c5a0
cmpl $0x0, (%rax)
jne 0xd3e5b
leaq 0x1a3bcf(%rip), %rax    # 0x277a24
movl $0x7fd, (%rax)          # imm = 0x7FD
leaq 0x29873e(%rip), %rax    # 0x36c5a0
movl $0x1, (%rax)
movslq -0xc(%rbp), %rcx
leaq 0x1ca31d(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0xffffffff, 0x218(%rax) # imm = 0xFFFFFFFF
movl -0x1c(%rbp), %eax
andl $0x880, %eax            # imm = 0x880
cmpl $0x0, %eax
je 0xd3ebb
cmpl $0x8, -0x10(%rbp)
jne 0xd3eb9
movslq -0xc(%rbp), %rcx
leaq 0x1ca2eb(%rip), %rax    # 0x29e190
imulq $0x348, %rcx, %rcx      # imm = 0x348
addq %rcx, %rax
movl $0x1, 0x218(%rax)
jmp 0xd3ebb
movl -0xc(%rbp), %edi
callq 0x80340
leaq 0x1ca222(%rip), %rax    # 0x29e0ec
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x1ca216(%rip), %rax    # 0x29e0ec
movl %ecx, (%rax)
leaq 0x298619(%rip), %rax    # 0x36c4f8
movl $0x17, (%rax)
jmp 0xd3ee7
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xd3d01
leaq 0x1ca1f0(%rip), %rax    # 0x29e0ec
movl (%rax), %edi
callq 0x82080
callq 0xd1f90
movl %eax, -0x20(%rbp)
leaq 0x1ae7b2(%rip), %rax    # 0x2826c4
movl $0x0, (%rax)
movl -0x20(%rbp), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0xe000, %eax           # imm = 0xE000
jne 0xd3f61
cvtsi2ssl -0x24(%rbp), %xmm0
movss 0xaf3ec(%rip), %xmm1    # 0x183320
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1ae785(%rip), %rax    # 0x2826c8
movsd %xmm0, (%rax)
leaq 0x1ae776(%rip), %rax    # 0x2826c4
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x1ae76a(%rip), %rax    # 0x2826c4
movl %ecx, (%rax)
jmp 0xd3fe9
movl -0x20(%rbp), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0x6000, %eax           # imm = 0x6000
jne 0xd3fa7
cvtsi2ssl -0x24(%rbp), %xmm0
movss 0xaf3a3(%rip), %xmm1    # 0x183320
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1ae744(%rip), %rax    # 0x2826d0
movsd %xmm0, (%rax)
leaq 0x1ae72d(%rip), %rax    # 0x2826c4
movl (%rax), %ecx
orl $0x2, %ecx
leaq 0x1ae721(%rip), %rax    # 0x2826c4
movl %ecx, (%rax)
jmp 0xd3fe7
cvtsi2ssl -0x24(%rbp), %xmm0
movss 0xaf36c(%rip), %xmm1    # 0x183320
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x1ae705(%rip), %rax    # 0x2826c8
movsd %xmm0, (%rax)
leaq 0x1ae702(%rip), %rax    # 0x2826d0
movsd %xmm0, (%rax)
leaq 0x1ae6eb(%rip), %rax    # 0x2826c4
movl (%rax), %ecx
orl $0x3, %ecx
leaq 0x1ae6df(%rip), %rax    # 0x2826c4
movl %ecx, (%rax)
jmp 0xd3fe9
callq 0x7a560
cmpl $0x0, -0x4(%rbp)
je 0xd413d
callq 0x7a560
cwtl
movl %eax, -0x28(%rbp)
callq 0x7a680
movl %eax, -0x30(%rbp)
cvtsi2sdl -0x28(%rbp), %xmm0
leaq 0x29798b(%rip), %rax    # 0x36b9a0
movsd %xmm0, (%rax)
leaq 0x2983f4(%rip), %rax    # 0x36c414
movl $0x6, (%rax)
leaq 0x2983fb(%rip), %rax    # 0x36c428
movl $0x6, (%rax)
callq 0x7a560
movw %ax, -0x2a(%rbp)
movswl -0x2a(%rbp), %eax
cvtsi2ss %eax, %xmm0
movss 0xaf320(%rip), %xmm1    # 0x18336c
divss %xmm1, %xmm0
movss %xmm0, -0x3c(%rbp)
leaq 0x2983d0(%rip), %rax    # 0x36c42c
cmpl $0x0, (%rax)
jne 0xd4077
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xd4077
jp 0xd4077
jmp 0xd4098
movss -0x3c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x297b71(%rip), %rax    # 0x36bbf8
movsd %xmm0, (%rax)
leaq 0x29839a(%rip), %rax    # 0x36c42c
movl $0x6c, (%rax)
callq 0x7a510
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xd40c7
leaq 0x2985cd(%rip), %rax    # 0x36c684
movl (%rax), %ecx
orl $0x1, %ecx
leaq 0x2985c1(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
jmp 0xd40dc
leaq 0x2985b6(%rip), %rax    # 0x36c684
movl (%rax), %ecx
andl $-0x2, %ecx
leaq 0x2985aa(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0xd40fe
leaq 0x298596(%rip), %rax    # 0x36c684
movl (%rax), %ecx
andl $-0x9, %ecx
leaq 0x29858a(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
jmp 0xd4113
leaq 0x29857f(%rip), %rax    # 0x36c684
movl (%rax), %ecx
orl $0x8, %ecx
leaq 0x298573(%rip), %rax    # 0x36c684
movl %ecx, (%rax)
leaq 0x2987fa(%rip), %rax    # 0x36c914
cmpl $0x0, (%rax)
jne 0xd4138
movl -0x34(%rbp), %ecx
andl $0x1f, %ecx
leaq 0x2987dc(%rip), %rax    # 0x36c908
movl %ecx, (%rax)
movl $0x9, %edi
callq 0x7a270
callq 0xd1ca0
callq 0xd1fc0
leaq 0x1c9f8f(%rip), %rax    # 0x29e0d8
leaq 0xb0e1a(%rip), %rcx     # 0x184f6a
movq %rcx, (%rax)
movl $0x3ed, %edi            # imm = 0x3ED
callq 0x9d790
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)