// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_brandy_message()
void get_brandy_message()
{
u08 c;
static int nmea_fmt = 0;

   // This routine buffers up an incoming Brandywine 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 == '$') || (c == '?') || isdigit(c)) {  // t-cmd and error messages also
         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
      nmea_fmt = 0;
      if(isdigit(c)) goto tcode;     // time code message
      else if(c == '?') goto tcode;  // error message
      nmea_fmt = 1;
      return;
   }
   else if(tsip_sync == 1) { // '$' has been seen, now build the message
      tcode:
      if((c == 0x0D) || (c == 0x0A)) goto nmea_end;  // message has no checksum

      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;
         tsip_buf[tsip_wptr] = 0;
      }
      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 >= '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(nmea_fmt == 0) ;  // t-cmd or error message
      else if(strstr((char *) &tsip_buf[0], "PRCCG,A")) ;  // rcvr sends wrong checksum!
      else if(nmea_fmt && (tsip_sync == 2) && (nmea_vfy_cksum != nmea_msg_cksum)) { // checksum error
         tsip_error |= CKSUM_ERROR;
         goto rst_msg;
      }

      decode_brandy_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 %r14
pushq %rbx
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x8aeea
callq 0x1ea0b
callq 0x584bd
movl %eax, %ebx
leaq 0x2834b2(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0x8ae3e
movb $0x0, 0x17a12(%rax)
leaq 0x2ad411(%rip), %r14    # 0x338256
movzwl (%r14), %eax
cmpq $0x3, %rax
ja 0x8afa7
leaq 0x944ee(%rip), %rcx     # 0x11f348
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x24, %bl
je 0x8ae7c
movzbl %bl, %eax
cmpl $0x3f, %eax
je 0x8ae7c
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x8afec
movw $0x1, (%r14)
callq 0x58672
leal -0x30(%rbx), %eax
cmpl $0xa, %eax
setb %al
cmpl $0x3f, %ebx
sete %cl
leaq 0x2ad3b5(%rip), %rdx    # 0x338252
xorl %esi, %esi
movw %si, (%rdx)
leaq 0x2ad3ab(%rip), %rdx    # 0x338254
movw %si, (%rdx)
movb %sil, 0x2e1c01(%rip)    # 0x36cab4
movb %sil, 0x2e1bfb(%rip)    # 0x36cab5
movb %sil, 0x2e6fcf(%rip)    # 0x371e90
orb %al, %cl
je 0x8af60
cmpb $0xa, %bl
je 0x8af04
movzbl %bl, %eax
cmpl $0xd, %eax
je 0x8af04
cmpl $0x2a, %eax
jne 0x8af69
movw $0x2, (%r14)
jmp 0x8afcd
popq %rbx
popq %r14
popq %rbp
jmp 0x1e66a
cmpb $0xa, %bl
je 0x8af04
movzbl %bl, %eax
cmpl $0xd, %eax
jne 0x8afd2
cmpb $0x1, 0x2e6f85(%rip)    # 0x371e90
jne 0x8af3f
leaq 0x2ac33c(%rip), %rdi    # 0x337250
leaq 0x988af(%rip), %rsi     # 0x1237ca
callq 0x9090
testq %rax, %rax
jne 0x8af3f
cmpw $0x2, (%r14)
jne 0x8af3f
movb 0x2e1b82(%rip), %al     # 0x36cab4
movl $0x4000, %edx           # imm = 0x4000
cmpb 0x2e1b78(%rip), %al     # 0x36cab5
jne 0x8af9e
callq 0x8ac5b
movl $0x1, 0x2e0d46(%rip)    # 0x36bc94
leaq 0x2ad2fd(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
jmp 0x8afc3
movb $0x1, 0x2e6f29(%rip)    # 0x371e90
jmp 0x8afcd
leaq 0x2ad2e2(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
movl $0x8000, %edx           # imm = 0x8000
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x8af9e
xorb %bl, 0x2e1b2e(%rip)     # 0x36cab4
leaq 0x1(%rax), %rdx
movw %dx, (%rcx)
leaq 0x2ac2bc(%rip), %rcx    # 0x337250
movb %bl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
jmp 0x8afcd
leaq 0x1b3fcb(%rip), %rax    # 0x23ef70
orl %edx, (%rax)
leaq 0x2ad2a4(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
movb %cl, 0x2e1af8(%rip)     # 0x36cab5
movb %cl, 0x2e1af1(%rip)     # 0x36cab4
movl $0x0, 0x2e1b17(%rip)    # 0x36cae4
popq %rbx
popq %r14
popq %rbp
retq
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x8aff3
movzbl 0x2e1ad4(%rip), %eax    # 0x36cab5
shll $0x4, %eax
addl $0xd0, %ebx
jmp 0x8b00b
xorl %eax, %eax
jmp 0x8ae90
leal -0x41(%rbx), %eax
cmpl $0x5, %eax
ja 0x8afa7
movzbl 0x2e1ab3(%rip), %eax    # 0x36cab5
shll $0x4, %eax
addl $0xc9, %ebx
orl %eax, %ebx
movb %bl, 0x2e1aa2(%rip)     # 0x36cab5
jmp 0x8afcd