// File: /workspace/github_cpp_makefile_star2_O1/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 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x96b83
callq 0x1ea2c
callq 0x584d5
leaq 0x2777bd(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x96b33
movb $0x0, 0x17a12(%rcx)
leaq 0x2a171c(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x8, %rcx
ja 0x96c82
leaq 0x88bde(%rip), %rdx     # 0x11f72c
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpl $0xa0, %eax
jne 0x96b68
movw $0x1, (%rbx)
callq 0x58682
leaq 0x2a16e3(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2a16d9(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0x96cae
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e6a0
leaq 0x2a16bd(%rip), %rsi    # 0x338252
movzwl (%rsi), %edx
movl $0x8000, %edi           # imm = 0x8000
cmpq $0xfff, %rdx            # imm = 0xFFF
ja 0x96c79
addw %ax, 0x2d5f3f(%rip)     # 0x36caf0
leal 0x1(%rdx), %edi
movw %di, (%rsi)
leaq 0x2a0692(%rip), %rsi    # 0x337250
movb %al, (%rsi,%rdx)
movl 0x2d5f31(%rip), %eax    # 0x36caf8
decl %eax
movl %eax, 0x2d5f29(%rip)    # 0x36caf8
testl %eax, %eax
jg 0x96cae
jmp 0x96c38
movl %eax, 0x2d5f19(%rip)    # 0x36caf8
movl %eax, 0x2d5f17(%rip)    # 0x36cafc
jmp 0x96c38
movl 0x2d5f0b(%rip), %edx    # 0x36caf8
shll $0x8, %edx
leal 0x1(%rcx), %esi
orl %eax, %edx
movl %edx, 0x2d5efd(%rip)    # 0x36caf8
movl %edx, 0x2d5efb(%rip)    # 0x36cafc
movw %si, (%rbx)
jne 0x96cae
leal 0x2(%rcx), %eax
jmp 0x96c3b
movw $0x8, (%rbx)
jmp 0x96cae
cmpl $0xa2, %eax
jne 0x96c82
leal 0x1(%rcx), %eax
movw %ax, (%rbx)
movw $0x0, 0x2d5ec1(%rip)    # 0x36caf0
jmp 0x96cae
movw %ax, 0x2d5eba(%rip)     # 0x36caf2
leal 0x1(%rcx), %eax
movw %ax, (%rbx)
jmp 0x96cae
movzwl 0x2d5eab(%rip), %ecx    # 0x36caf2
andl $0x7f, %ecx
shll $0x8, %ecx
orl %eax, %ecx
movw %cx, 0x2d5e9c(%rip)     # 0x36caf2
movzwl 0x2d5e93(%rip), %eax    # 0x36caf0
andl $0x7fff, %eax           # imm = 0x7FFF
movw %ax, 0x2d5e87(%rip)     # 0x36caf0
movl $0x4000, %edi           # imm = 0x4000
cmpl %eax, %ecx
jne 0x96c79
movw $0x7, (%rbx)
jmp 0x96cae
leaq 0x1a82f0(%rip), %rax    # 0x23ef70
orl %edi, (%rax)
leaq 0x2a15c9(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
movw %cx, 0x2d5e58(%rip)     # 0x36caf0
jmp 0x96cae
callq 0x969dc
movl $0x1, 0x2d4feb(%rip)    # 0x36bc94
movw $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq