// File: /workspace/github_cpp_makefile_star2_O1/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 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x86598
callq 0x1ea2c
callq 0x584d5
leaq 0x287db2(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x8653e
movb $0x0, 0x17a12(%rcx)
leaq 0x2b1d11(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x3, %rcx
ja 0x866af
leaq 0x98b67(%rip), %rdx     # 0x11f0c0
movslq (%rdx,%rcx,4), %rsi
addq %rdx, %rsi
jmpq *%rsi
cmpl $0x24, %eax
jne 0x86571
movw $0x1, (%rbx)
callq 0x58682
leaq 0x2b1cda(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2b1cd0(%rip), %rax    # 0x338254
movw %cx, (%rax)
movb %cl, 0x2e6527(%rip)     # 0x36cab4
movb %cl, 0x2e6522(%rip)     # 0x36cab5
jmp 0x866d4
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e6a0
cmpl $0xa, %eax
je 0x865f2
cmpl $0xd, %eax
je 0x866d4
cmpl $0x2a, %eax
jne 0x86653
movw $0x2, (%rbx)
jmp 0x866d4
cmpl $0xa, %eax
je 0x865f2
cmpl $0xd, %eax
je 0x866d4
leal -0x30(%rax), %ecx
cmpl $0x9, %ecx
ja 0x8668e
movzbl 0x2e64d0(%rip), %ecx    # 0x36cab5
shll $0x4, %ecx
addl $0xd0, %eax
jmp 0x866a5
cmpw $0x2, %cx
jne 0x8660b
movb 0x2e64b6(%rip), %al     # 0x36cab4
movl $0x4000, %esi           # imm = 0x4000
cmpb 0x2e64ac(%rip), %al     # 0x36cab5
jne 0x86683
leaq 0x1922be(%rip), %rax    # 0x2188d0
movq (%rax), %rax
cmpq $0x200000, %rax         # imm = 0x200000
je 0x8662c
cmpq $0x100000, %rax         # imm = 0x100000
jne 0x86633
callq 0x866db
jmp 0x86638
callq 0x86ca7
jmp 0x86638
callq 0x84fb4
movl $0x1, 0x2e5652(%rip)    # 0x36bc94
leaq 0x2b1c09(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
jmp 0x866ca
leaq 0x2b1bf8(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
movl $0x8000, %esi           # imm = 0x8000
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x86683
xorb %al, 0x2e6443(%rip)     # 0x36cab4
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b0bd2(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x866d4
leaq 0x1b88e6(%rip), %rax    # 0x23ef70
orl %esi, (%rax)
jmp 0x866af
leal -0x41(%rax), %ecx
cmpl $0x5, %ecx
ja 0x866af
movzbl 0x2e6418(%rip), %ecx    # 0x36cab5
shll $0x4, %ecx
addl $0xc9, %eax
orl %ecx, %eax
movb %al, 0x2e6408(%rip)     # 0x36cab5
jmp 0x866d4
leaq 0x2b1b9c(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
movb %cl, 0x2e63f1(%rip)     # 0x36cab5
movb %cl, 0x2e63ea(%rip)     # 0x36cab4
movl $0x0, 0x2e6410(%rip)    # 0x36cae4
addq $0x8, %rsp
popq %rbx
popq %rbp
retq