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

   // This routine buffers up an incoming NMEA message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_nmea_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 '$'
      if(c == '$') {
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      nmea_vfy_cksum = 0;  // the calculated message checksum
      nmea_msg_cksum = 0;  // the checksum in the message
      return;
   }
   else if(tsip_sync == 1) { // '$' has been seen, now build the message
//if((c == 0x0D) || (c == 0x0A)) goto nmea_end;
      if(c == 0x0D) return;
      if(c == 0x0A) goto nmea_end;

      if(c == '*') tsip_sync = 2;  // message checksum follows
      else if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         nmea_vfy_cksum ^= c;
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 2) {  // getting message checksum chars
//if((c == 0x0D) || (c == 0x0A)) goto nmea_end;
      if(c == 0x0D) return;
      if(c == 0x0A) goto nmea_end;

      if     ((c >= '0') && (c <= '9')) nmea_msg_cksum = (nmea_msg_cksum << 4) | (c-'0');
      else if((c >= 'A') && (c <= 'F')) nmea_msg_cksum = (nmea_msg_cksum << 4) | ((c-'A')+10);
      else goto rst_msg;
   }
   else if(tsip_sync == 3) {  // end of message
      nmea_end:
      if((tsip_sync == 2) && (nmea_vfy_cksum != nmea_msg_cksum)) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }

      if(rcvr_type == ZYFER_RCVR)     decode_zyfer_message(); // message checksum matches, process the message
      else if(rcvr_type == TRUE_RCVR) decode_true_message();
      else                            decode_nmea_msg();      // message checksum matches, process the message
      packet_end = 1;

      tsip_wptr = 0;     // prepare for next message
      tsip_sync = 0;
      venus_nmea = 0;
   }
   else {     // should never happen, prepare for next message
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      nmea_vfy_cksum = nmea_msg_cksum = 0; // init received message checksum
      venus_nmea = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xb84a6
movl $0xa, %edi
callq 0x2b610
jmp 0xb8767
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x2b5001(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xb84d6
leaq 0x2b4ff1(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2def59(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xb852a
movzbl -0x1(%rbp), %eax
cmpl $0x24, %eax
jne 0xb84ff
leaq 0x2def41(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
leaq 0x2def2c(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2def22(%rip), %rax    # 0x397434
movw $0x0, (%rax)
movb $0x0, 0x313776(%rip)    # 0x3cbc94
movb $0x0, 0x313770(%rip)    # 0x3cbc95
jmp 0xb8767
leaq 0x2def05(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xb85e7
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
jne 0xb854b
jmp 0xb8767
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xb8559
jmp 0xb8691
movzbl -0x1(%rbp), %eax
cmpl $0x2a, %eax
jne 0xb8570
leaq 0x2deecd(%rip), %rax    # 0x397436
movw $0x2, (%rax)
jmp 0xb85e2
leaq 0x2deebb(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xb85c3
movzbl -0x1(%rbp), %ecx
movzbl 0x313708(%rip), %eax    # 0x3cbc94
xorl %ecx, %eax
movb %al, 0x313700(%rip)     # 0x3cbc94
movb -0x1(%rbp), %dl
leaq 0x2dee94(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2dee83(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2dde72(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
jmp 0xb85e0
leaq 0x1e5b86(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e5b77(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xb8731
jmp 0xb85e2
jmp 0xb8765
leaq 0x2dee48(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xb867c
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
jne 0xb8608
jmp 0xb8767
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xb8613
jmp 0xb8691
movzbl -0x1(%rbp), %eax
cmpl $0x30, %eax
jl 0xb8640
movzbl -0x1(%rbp), %eax
cmpl $0x39, %eax
jg 0xb8640
movzbl 0x313669(%rip), %eax    # 0x3cbc95
shll $0x4, %eax
movzbl -0x1(%rbp), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movb %al, 0x313657(%rip)     # 0x3cbc95
jmp 0xb8677
movzbl -0x1(%rbp), %eax
cmpl $0x41, %eax
jl 0xb8670
movzbl -0x1(%rbp), %eax
cmpl $0x46, %eax
jg 0xb8670
movzbl 0x31363c(%rip), %eax    # 0x3cbc95
shll $0x4, %eax
movzbl -0x1(%rbp), %ecx
subl $0x41, %ecx
addl $0xa, %ecx
orl %ecx, %eax
movb %al, 0x313627(%rip)     # 0x3cbc95
jmp 0xb8675
jmp 0xb8731
jmp 0xb8677
jmp 0xb8763
leaq 0x2dedb3(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xb872f
jmp 0xb8691
leaq 0x2ded9e(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xb86cc
movzbl 0x3135ed(%rip), %eax    # 0x3cbc94
movzbl 0x3135e7(%rip), %ecx    # 0x3cbc95
cmpl %ecx, %eax
je 0xb86cc
leaq 0x1e5a97(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
leaq 0x1e5a88(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xb8731
leaq 0x1bf3dd(%rip), %rax    # 0x277ab0
cmpq $0x100000, (%rax)       # imm = 0x100000
jne 0xb86e3
callq 0xb8770
jmp 0xb8701
leaq 0x1bf3c6(%rip), %rax    # 0x277ab0
cmpq $0x200000, (%rax)       # imm = 0x200000
jne 0xb86fa
callq 0xb8f10
jmp 0xb86ff
callq 0xb6840
jmp 0xb8701
movl $0x1, 0x312769(%rip)    # 0x3cae74
leaq 0x2ded20(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2ded18(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movl $0x0, 0x313597(%rip)    # 0x3cbcc4
jmp 0xb8761
jmp 0xb8731
leaq 0x2decfa(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2decf2(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movb $0x0, 0x313545(%rip)    # 0x3cbc95
movb $0x0, 0x31353d(%rip)    # 0x3cbc94
movl $0x0, 0x313563(%rip)    # 0x3cbcc4
jmp 0xb8763
jmp 0xb8765
jmp 0xb8767
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)