// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_sirf_message()
void get_sirf_message()
{
u08 c;

   // This routine buffers up an incoming UBX message.  When the end of the
   // message is seen, the message is parsed and decoded with parse_ubx_msg()

   if(SERIAL_DATA_AVAILABLE(RCVR_PORT) == 0) {
      check_com_timer(RCVR_PORT);
      return;
   }
   else {
      reset_com_timer(RCVR_PORT);
   }

   c = get_com_char();
   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }


   if(tsip_sync == 0) {      // syncing to start of message, search for a 0xA0
      if(c == 0xA0) {
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // 0xA0 has been seen, now checking next byte
      if(c != 0xA2) goto rst_msg;
      ++tsip_sync;           // 0xA2 seen... so accumulate the message
      sirf_rx_cksum = 0;     // init received message checksum
   }
   else if(tsip_sync == 2) { // high byte of payload length
      sirf_rx_len = ((u32) c);
      sirf_msg_len = sirf_rx_len;
      ++tsip_sync;
   }
   else if(tsip_sync == 3) {    // low byte of payload length
      sirf_rx_len *= 256;
      sirf_rx_len += (((u32) c) & 0xFF);
      sirf_msg_len = sirf_rx_len;
      ++tsip_sync;
      if(sirf_rx_len == 0) ++tsip_sync;  // message has no payload
   }
   else if(tsip_sync == 4) {   // get sirf message payload
      if(tsip_wptr < MAX_TSIP) {  // so add it to the message buffer
         sirf_rx_cksum += c;
         tsip_buf[tsip_wptr++] = c;
         --sirf_rx_len;
         if((int) sirf_rx_len <= 0) ++tsip_sync;  // message payload processed, now get checksums
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 5) {  // first (high) byte of message checksum
      sirf_msg_cksum = c;
      ++tsip_sync;
   }
   else if(tsip_sync == 6) {  // last byte of message checksum, end of sirf message
      sirf_msg_cksum = (sirf_msg_cksum * 256) + (((u16) c) & 0xFF);
      sirf_msg_cksum &= 0x7FFF;
      sirf_rx_cksum &= 0x7FFF;

      if(sirf_msg_cksum != sirf_rx_cksum) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }
      tsip_sync = 7;
//    tsip_sync = 0;
//    decode_sirf_msg();  // message checksum matches, process the message
//    packet_end = 1;
   }
   else if(tsip_sync == 7) {  // end-of-message bytes
      tsip_sync = 8;
   }
   else if(tsip_sync == 8) {  // end-of-message bytes 
      decode_sirf_msg();  // message checksum matches, process the message
      packet_end = 1;
      tsip_sync = 0;
   }
   else {     // should never happen
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      sirf_rx_cksum = 0; // init received message checksum
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x96c9c
callq 0x1ea0b
callq 0x584bd
leaq 0x2776a4(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x96c4c
movb $0x0, 0x17a12(%rcx)
leaq 0x2a1603(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x8, %rcx
ja 0x96da8
leaq 0x88b9d(%rip), %rdx     # 0x11f804
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0xa0, %eax
jne 0x96c81
movw $0x1, (%rbx)
callq 0x58672
leaq 0x2a15ca(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2a15c0(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0x96dd4
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e66a
leaq 0x2a15a4(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x96d9f
addw %ax, 0x2d5e26(%rip)     # 0x36caf0
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2a0579(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movl 0x2d5e18(%rip), %eax    # 0x36caf8
decl %eax
movl %eax, 0x2d5e10(%rip)    # 0x36caf8
testl %eax, %eax
jg 0x96dd4
movw $0x5, (%rbx)
jmp 0x96dd4
movl %eax, 0x2d5df8(%rip)    # 0x36caf8
movl %eax, 0x2d5df6(%rip)    # 0x36cafc
movw $0x3, (%rbx)
jmp 0x96dd4
movl 0x2d5de2(%rip), %ecx    # 0x36caf8
shll $0x8, %ecx
xorl %edx, %edx
orl %eax, %ecx
movl %ecx, 0x2d5dd5(%rip)    # 0x36caf8
movl %ecx, 0x2d5dd3(%rip)    # 0x36cafc
sete %dl
orl $0x4, %edx
movw %dx, (%rbx)
jmp 0x96dd4
movw $0x8, (%rbx)
jmp 0x96dd4
cmpl $0xa2, %eax
jne 0x96da8
movw $0x2, (%rbx)
movw $0x0, 0x2d5d9a(%rip)    # 0x36caf0
jmp 0x96dd4
movw %ax, 0x2d5d93(%rip)     # 0x36caf2
movw $0x6, (%rbx)
jmp 0x96dd4
movzwl 0x2d5d85(%rip), %ecx    # 0x36caf2
andl $0x7f, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movw %cx, 0x2d5d76(%rip)     # 0x36caf2
movzwl 0x2d5d6d(%rip), %eax    # 0x36caf0
andl $0x7fff, %eax           # imm = 0x7FFF
movw %ax, 0x2d5d61(%rip)     # 0x36caf0
movl $0x4000, %esi           # imm = 0x4000
cmpl %eax, %ecx
jne 0x96d9f
movw $0x7, (%rbx)
jmp 0x96dd4
leaq 0x1a81ca(%rip), %rax    # 0x23ef70
orl %esi, (%rax)
leaq 0x2a14a3(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
movw %cx, 0x2d5d32(%rip)     # 0x36caf0
jmp 0x96dd4
callq 0x96af5
movl $0x1, 0x2d4ec5(%rip)    # 0x36bc94
movw $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq