// File: /workspace/github_cpp_makefile_star2_O2/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, 0x2cc187(%rip)    # 0x356ae4
je 0x8a968
popq %rbx
popq %r14
popq %rbp
jmp 0x7a6ee
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x8a9d9
callq 0x1d93f
callq 0x51891
leaq 0x26d958(%rip), %rcx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rcx)
je 0x8a998
movb $0x0, 0x17a12(%rcx)
leaq 0x2978b7(%rip), %rbx    # 0x322256
movzwl (%rbx), %ecx
cmpq $0x7, %rcx
ja 0x8aad2
leaq 0x7ee4d(%rip), %rdx     # 0x109800
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpb $-0x60, %al
je 0x8aaea
movzbl %al, %eax
cmpl $0x24, %eax
jne 0x8aafe
pushq $0x1
popq %r14
jmp 0x8aaed
popq %rbx
popq %r14
popq %rbp
jmp 0x1d61b
leaq 0x297869(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x8aac9
xorb %al, 0x2cc0d0(%rip)     # 0x356ad4
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x29683f(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
movl 0x2cc0be(%rip), %eax    # 0x356ad8
decl %eax
movl %eax, 0x2cc0b6(%rip)    # 0x356ad8
testl %eax, %eax
jg 0x8ab22
movw $0x5, (%rbx)
jmp 0x8ab22
movl %eax, 0x2cc09e(%rip)    # 0x356ad8
movl %eax, 0x2cc09c(%rip)    # 0x356adc
movw $0x3, (%rbx)
jmp 0x8ab22
movl 0x2cc088(%rip), %ecx    # 0x356ad8
shll $0x8, %ecx
xorl %edx, %edx
orl %eax, %ecx
movl %ecx, 0x2cc07b(%rip)    # 0x356ad8
movl %ecx, 0x2cc079(%rip)    # 0x356adc
sete %dl
orl $0x4, %edx
movw %dx, (%rbx)
jmp 0x8ab22
callq 0x8a7fc
movl $0x1, 0x2cb214(%rip)    # 0x355c94
jmp 0x8aadd
cmpl $0xa1, %eax
jne 0x8aad2
movw $0x2, (%rbx)
movb $0x0, 0x2cc03f(%rip)    # 0x356ad4
jmp 0x8ab22
leaq 0x2967af(%rip), %rcx    # 0x321250
movb (%rcx), %cl
movb %cl, 0x2cc037(%rip)     # 0x356ae0
movb 0x2cc025(%rip), %cl     # 0x356ad4
movl %ecx, %edx
xorb %al, %dl
movb %dl, 0x2cc01b(%rip)     # 0x356ad4
movl $0x4000, %esi           # imm = 0x4000
cmpb %al, %cl
jne 0x8aac9
movw $0x6, (%rbx)
jmp 0x8ab22
leaq 0x19e4a0(%rip), %rax    # 0x228f70
orl %esi, (%rax)
leaq 0x297779(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%rbx)
jmp 0x8ab22
movw $0x7, (%rbx)
jmp 0x8ab22
xorl %r14d, %r14d
movw $0x1, (%rbx)
callq 0x51a2f
movl %r14d, 0x2cbfe6(%rip)   # 0x356ae4
xorl %eax, %eax
movb %al, 0x2cbfae(%rip)     # 0x356ab4
movb %al, 0x2cbfa9(%rip)     # 0x356ab5
leaq 0x29773f(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x297736(%rip), %rax    # 0x322254
andw $0x0, (%rax)
popq %rbx
popq %r14
popq %rbp
retq