// File: /workspace/github_cpp_makefile_star2_O1/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, 0x2d40e3(%rip)    # 0x36cae4
je 0x98a0c
popq %rbx
popq %r14
popq %rbp
jmp 0x86504
movl $0xa, %edi
callq 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x98a83
callq 0x1ea2c
callq 0x584d5
leaq 0x2758b0(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x98a40
movb $0x0, 0x17a12(%rcx)
leaq 0x29f80f(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x7, %rcx
ja 0x98b84
leaq 0x86d89(%rip), %rdx     # 0x11f7e4
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpl $0xa0, %eax
je 0x98b9c
cmpl $0x24, %eax
jne 0x98bb0
movl $0x1, %r14d
jmp 0x98b9f
popq %rbx
popq %r14
popq %rbp
jmp 0x1e6a0
leaq 0x29f7bf(%rip), %rsi    # 0x338252
movzwl (%rsi), %edx
movl $0x8000, %edi           # imm = 0x8000
cmpq $0xfff, %rdx            # imm = 0xFFF
ja 0x98b7b
xorb %al, 0x2d4026(%rip)     # 0x36cad4
leal 0x1(%rdx), %edi
movw %di, (%rsi)
leaq 0x29e795(%rip), %rsi    # 0x337250
movb %al, (%rsi,%rdx)
movl 0x2d4014(%rip), %eax    # 0x36cad8
decl %eax
movl %eax, 0x2d400c(%rip)    # 0x36cad8
testl %eax, %eax
jg 0x98bd2
jmp 0x98ae2
movl %eax, 0x2d3ffc(%rip)    # 0x36cad8
movl %eax, 0x2d3ffa(%rip)    # 0x36cadc
leal 0x1(%rcx), %eax
jmp 0x98b0d
movl 0x2d3feb(%rip), %edx    # 0x36cad8
shll $0x8, %edx
leal 0x1(%rcx), %esi
orl %eax, %edx
movl %edx, 0x2d3fdd(%rip)    # 0x36cad8
movl %edx, 0x2d3fdb(%rip)    # 0x36cadc
movw %si, (%rbx)
jne 0x98bd2
leal 0x2(%rcx), %eax
movw %ax, (%rbx)
jmp 0x98bd2
callq 0x9884b
movl $0x1, 0x2d3170(%rip)    # 0x36bc94
movw $0x0, (%rbx)
jmp 0x98bd2
cmpl $0xa1, %eax
jne 0x98b84
leal 0x1(%rcx), %eax
movw %ax, (%rbx)
movb $0x0, 0x2d3f92(%rip)    # 0x36cad4
jmp 0x98bd2
movw $0x0, (%rbx)
leaq 0x29e6fd(%rip), %rcx    # 0x337250
movb (%rcx), %cl
movb %cl, 0x2d3f85(%rip)     # 0x36cae0
movb 0x2d3f73(%rip), %cl     # 0x36cad4
movl %ecx, %edx
xorb %al, %dl
movb %dl, 0x2d3f69(%rip)     # 0x36cad4
movl $0x4000, %edi           # imm = 0x4000
cmpb %al, %cl
jne 0x98b7b
movw $0x6, (%rbx)
jmp 0x98bd2
leaq 0x1a63ee(%rip), %rax    # 0x23ef70
orl %edi, (%rax)
leaq 0x29f6c7(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
jmp 0x98bd2
movw $0x7, (%rbx)
jmp 0x98bd2
xorl %r14d, %r14d
movw $0x1, (%rbx)
callq 0x58682
movl %r14d, 0x2d3f34(%rip)   # 0x36cae4
xorl %eax, %eax
movb %al, 0x2d3efc(%rip)     # 0x36cab4
movb %al, 0x2d3ef7(%rip)     # 0x36cab5
leaq 0x29f68d(%rip), %rcx    # 0x338252
movw %ax, (%rcx)
leaq 0x29f685(%rip), %rcx    # 0x338254
movw %ax, (%rcx)
popq %rbx
popq %r14
popq %rbp
retq