// File: 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
subq $0x10, %rsp
cmpl $0x0, 0x2fc005(%rip)    # 0x3cbcc4
je 0xcfccb
callq 0xb8480
jmp 0xd003a
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xcfce9
movl $0xa, %edi
callq 0x2b610
jmp 0xd003a
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x29d7be(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xcfd19
leaq 0x29d7ae(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2c7716(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xcfda1
movzbl -0x1(%rbp), %eax
cmpl $0xa0, %eax
jne 0xcfd50
leaq 0x2c76fc(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
movl $0x0, 0x2fbf76(%rip)    # 0x3cbcc4
jmp 0xcfd76
movzbl -0x1(%rbp), %eax
cmpl $0x24, %eax
jne 0xcfd74
leaq 0x2c76d6(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
movl $0x1, 0x2fbf50(%rip)    # 0x3cbcc4
jmp 0xcfd76
movb $0x0, 0x2fbf17(%rip)    # 0x3cbc94
movb $0x0, 0x2fbf11(%rip)    # 0x3cbc95
leaq 0x2c76a7(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2c769d(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xd003a
leaq 0x2c768e(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xcfde4
movzbl -0x1(%rbp), %eax
cmpl $0xa1, %eax
je 0xcfdc0
jmp 0xd0014
leaq 0x2c766f(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2c7661(%rip), %rax    # 0x397436
movw %cx, (%rax)
movb $0x0, 0x2fbed5(%rip)    # 0x3cbcb4
jmp 0xd0038
leaq 0x2c764b(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xcfe26
movzbl -0x1(%rbp), %eax
movl %eax, 0x2fbebb(%rip)    # 0x3cbcb8
movl 0x2fbeb5(%rip), %eax    # 0x3cbcb8
movl %eax, 0x2fbeb3(%rip)    # 0x3cbcbc
leaq 0x2c7626(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2c7618(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xd0036
leaq 0x2c7609(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xcfea3
movl 0x2fbe7d(%rip), %eax    # 0x3cbcb8
shll $0x8, %eax
movl %eax, 0x2fbe74(%rip)    # 0x3cbcb8
movzbl -0x1(%rbp), %eax
andl $0xff, %eax
addl 0x2fbe65(%rip), %eax    # 0x3cbcb8
movl %eax, 0x2fbe5f(%rip)    # 0x3cbcb8
movl 0x2fbe59(%rip), %eax    # 0x3cbcb8
movl %eax, 0x2fbe57(%rip)    # 0x3cbcbc
leaq 0x2c75ca(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2c75bc(%rip), %rax    # 0x397436
movw %cx, (%rax)
cmpl $0x0, 0x2fbe34(%rip)    # 0x3cbcb8
jne 0xcfe9e
leaq 0x2c75a9(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2c759b(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xd0034
leaq 0x2c758c(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x4, %eax
jne 0xcff5b
leaq 0x2c7575(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xcff39
movzbl -0x1(%rbp), %ecx
movzbl 0x2fbde2(%rip), %eax    # 0x3cbcb4
xorl %ecx, %eax
movb %al, 0x2fbdda(%rip)     # 0x3cbcb4
movb -0x1(%rbp), %dl
leaq 0x2c754e(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2c753d(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2c652c(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
movl 0x2fbdab(%rip), %eax    # 0x3cbcb8
addl $-0x1, %eax
movl %eax, 0x2fbda2(%rip)    # 0x3cbcb8
cmpl $0x0, 0x2fbd9b(%rip)    # 0x3cbcb8
jg 0xcff37
leaq 0x2c7510(%rip), %rax    # 0x397436
movw (%rax), %cx
addw $0x1, %cx
leaq 0x2c7502(%rip), %rax    # 0x397436
movw %cx, (%rax)
jmp 0xcff56
leaq 0x1ce210(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1ce201(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xd0014
jmp 0xd0032
leaq 0x2c74d4(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x5, %eax
jne 0xcffc9
leaq 0x2c74c5(%rip), %rax    # 0x397436
movw $0x0, (%rax)
leaq 0x2c64b3(%rip), %rax    # 0x396430
movb (%rax), %al
movb %al, 0x2fbd3b(%rip)     # 0x3cbcc0
movzbl -0x1(%rbp), %ecx
movzbl 0x2fbd24(%rip), %eax    # 0x3cbcb4
xorl %ecx, %eax
movb %al, 0x2fbd1c(%rip)     # 0x3cbcb4
cmpb $0x0, 0x2fbd15(%rip)    # 0x3cbcb4
je 0xcffbb
leaq 0x1ce1a8(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
leaq 0x1ce199(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xd0014
leaq 0x2c7474(%rip), %rax    # 0x397436
movw $0x6, (%rax)
jmp 0xd0030
leaq 0x2c7466(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x6, %eax
jne 0xcffe6
leaq 0x2c7457(%rip), %rax    # 0x397436
movw $0x7, (%rax)
jmp 0xd002e
leaq 0x2c7449(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x7, %eax
jne 0xd0012
callq 0xcfa40
movl $0x1, 0x2fae70(%rip)    # 0x3cae74
leaq 0x2c742b(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xd002c
jmp 0xd0014
leaq 0x2c7417(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2c740f(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xd002e
jmp 0xd0030
jmp 0xd0032
jmp 0xd0034
jmp 0xd0036
jmp 0xd0038
jmp 0xd003a
addq $0x10, %rsp
popq %rbp
retq