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

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

if(venus_nmea) {   // vvvvv - mixed NMEA and Venus binary messages
   get_nmea_message();
   return;
}

   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 0xA1
      if(c == 0xA0) {
         tsip_sync = 1;
         get_sync_time();
         venus_nmea = 0;
      }
      else if(c == '$') {  // mixed Venus binary and NMEA messages
         tsip_sync = 1;
         get_sync_time();
         venus_nmea = 1;
      }
      nmea_vfy_cksum = 0;  // the calculated message checksum
      nmea_msg_cksum = 0;  // the checksum in the message
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // 0xA1 has been seen, now checking next byte
      if(c != 0xA1) goto rst_msg;
      ++tsip_sync;           // 0xA0 0xA1 seen... so accumulate the message
      venus_vfy_cksum = 0;
   }
   else if(tsip_sync == 2) {    // payload len high byte
      venus_rx_len = ((u32) c);
      venus_msg_len = venus_rx_len;
      ++tsip_sync;
   }
   else if(tsip_sync == 3) {    // payload len low byte
      venus_rx_len *= 256;
      venus_rx_len += (((u32) c) & 0xFF);
      venus_msg_len = venus_rx_len;
      ++tsip_sync;
      if(venus_rx_len == 0) ++tsip_sync;
   }
   else if(tsip_sync == 4) {   // get Venus message payload
      if(tsip_wptr < MAX_TSIP) {  // so add it to the message buffer
         venus_vfy_cksum ^= c;
         tsip_buf[tsip_wptr++] = c;
         --venus_rx_len;
         if((int) venus_rx_len <= 0) {
            ++tsip_sync;  // message payload processed, now get checksums
         }
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 5) {  // message checksum, end of venus message
      tsip_sync = 0;
venus_msg_id = tsip_buf[0];
// fprintf(debug_file, "venus msg %02X  len:%02X  vchk:%02X  c=%02X\n", venus_msg_id, venus_msg_len, venus_vfy_cksum, c);
      venus_vfy_cksum ^= c;
      if(venus_vfy_cksum) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }
      tsip_sync = 6;

      if(0) {
         decode_venus_msg();  // message checksum matches, process the message
         packet_end = 1;
         tsip_sync = 0;
      }
   }
   else if(tsip_sync == 6) {  // 0x0D
      tsip_sync = 7;
   }
   else if(tsip_sync == 7) {  // 0x0A
      decode_venus_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;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
cmpl $0x0, 0x2d3fd7(%rip)    # 0x36cae4
je 0x98b18
popq %rbx
popq %r14
popq %rbp
jmp 0x86477
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x98b8f
callq 0x1ea0b
callq 0x584bd
leaq 0x2757a4(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x98b4c
movb $0x0, 0x17a12(%rcx)
leaq 0x29f703(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x7, %rcx
ja 0x98c90
leaq 0x86d55(%rip), %rdx     # 0x11f8bc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpb $-0x60, %al
je 0x98ca8
movzbl %al, %eax
cmpl $0x24, %eax
jne 0x98cbc
movl $0x1, %r14d
jmp 0x98cab
popq %rbx
popq %r14
popq %rbp
jmp 0x1e66a
leaq 0x29f6b3(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x98c87
xorb %al, 0x2d3f1a(%rip)     # 0x36cad4
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x29e689(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movl 0x2d3f08(%rip), %eax    # 0x36cad8
decl %eax
movl %eax, 0x2d3f00(%rip)    # 0x36cad8
testl %eax, %eax
jg 0x98cde
movw $0x5, (%rbx)
jmp 0x98cde
movl %eax, 0x2d3ee8(%rip)    # 0x36cad8
movl %eax, 0x2d3ee6(%rip)    # 0x36cadc
movw $0x3, (%rbx)
jmp 0x98cde
movl 0x2d3ed2(%rip), %ecx    # 0x36cad8
shll $0x8, %ecx
xorl %edx, %edx
orl %eax, %ecx
movl %ecx, 0x2d3ec5(%rip)    # 0x36cad8
movl %ecx, 0x2d3ec3(%rip)    # 0x36cadc
sete %dl
orl $0x4, %edx
movw %dx, (%rbx)
jmp 0x98cde
callq 0x98957
movl $0x1, 0x2d305e(%rip)    # 0x36bc94
movw $0x0, (%rbx)
jmp 0x98cde
cmpl $0xa1, %eax
jne 0x98c90
movw $0x2, (%rbx)
movb $0x0, 0x2d3e81(%rip)    # 0x36cad4
jmp 0x98cde
leaq 0x29e5f1(%rip), %rcx    # 0x337250
movb (%rcx), %cl
movb %cl, 0x2d3e79(%rip)     # 0x36cae0
movb 0x2d3e67(%rip), %cl     # 0x36cad4
movl %ecx, %edx
xorb %al, %dl
movb %dl, 0x2d3e5d(%rip)     # 0x36cad4
movl $0x4000, %esi           # imm = 0x4000
cmpb %al, %cl
jne 0x98c87
movw $0x6, (%rbx)
jmp 0x98cde
leaq 0x1a62e2(%rip), %rax    # 0x23ef70
orl %esi, (%rax)
leaq 0x29f5bb(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
jmp 0x98cde
movw $0x7, (%rbx)
jmp 0x98cde
xorl %r14d, %r14d
movw $0x1, (%rbx)
callq 0x58672
movl %r14d, 0x2d3e28(%rip)   # 0x36cae4
xorl %eax, %eax
movb %al, 0x2d3df0(%rip)     # 0x36cab4
movb %al, 0x2d3deb(%rip)     # 0x36cab5
leaq 0x29f581(%rip), %rcx    # 0x338252
movw %ax, (%rcx)
leaq 0x29f579(%rip), %rcx    # 0x338254
movw %ax, (%rcx)
popq %rbx
popq %r14
popq %rbp
retq