// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x8650b
callq 0x1ea0b
callq 0x584bd
leaq 0x287e3f(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x864b1
movb $0x0, 0x17a12(%rcx)
leaq 0x2b1d9e(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x3, %rcx
ja 0x86620
leaq 0x98cb4(%rip), %rdx     # 0x11f180
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x24, %eax
jne 0x864e4
movw $0x1, (%rbx)
callq 0x58672
leaq 0x2b1d67(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2b1d5d(%rip), %rax    # 0x338254
movw %cx, (%rax)
movb %cl, 0x2e65b4(%rip)     # 0x36cab4
movb %cl, 0x2e65af(%rip)     # 0x36cab5
jmp 0x86645
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e66a
cmpb $0xa, %al
je 0x8657c
movzbl %al, %ecx
cmpl $0xd, %ecx
je 0x86645
cmpl $0x2a, %ecx
jne 0x865c4
movw $0x2, (%rbx)
jmp 0x86645
cmpb $0xa, %al
je 0x86569
movzbl %al, %ecx
cmpl $0xd, %ecx
je 0x86645
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x865ff
movzbl 0x2e6559(%rip), %ecx    # 0x36cab5
shll $0x4, %ecx
addl $0xd0, %eax
jmp 0x86616
movb 0x2e6545(%rip), %al     # 0x36cab4
movl $0x4000, %esi           # imm = 0x4000
cmpb 0x2e653b(%rip), %al     # 0x36cab5
jne 0x865f4
leaq 0x19234d(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x200000, %rax         # imm = 0x200000
je 0x8659d
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x865a4
callq 0x8664c
jmp 0x865a9
callq 0x86c18
jmp 0x865a9
callq 0x84f17
movl $0x1, 0x2e56e1(%rip)    # 0x36bc94
leaq 0x2b1c98(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
jmp 0x8663b
leaq 0x2b1c87(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x865f4
xorb %al, 0x2e64d2(%rip)     # 0x36cab4
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b0c61(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x86645
leaq 0x1b8975(%rip), %rax    # 0x23ef70
orl %esi, (%rax)
jmp 0x86620
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x86620
movzbl 0x2e64a7(%rip), %ecx    # 0x36cab5
shll $0x4, %ecx
addl $0xc9, %eax
orl %ecx, %eax
movb %al, 0x2e6497(%rip)     # 0x36cab5
jmp 0x86645
leaq 0x2b1c2b(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
movb %cl, 0x2e6480(%rip)     # 0x36cab5
movb %cl, 0x2e6479(%rip)     # 0x36cab4
movl $0x0, 0x2e649f(%rip)    # 0x36cae4
addq $0x8, %rsp
popq %rbx
popq %rbp
retq