// File: /workspace/github_cpp_makefile_star2_O1/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 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x8aef2
callq 0x1ea2c
callq 0x584d5
movl %eax, %ebx
leaq 0x28349d(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0x8ae53
movb $0x0, 0x17a12(%rax)
leaq 0x2ad3fc(%rip), %r14    # 0x338256
movzwl (%r14), %eax
cmpq $0x3, %rax
ja 0x8afac
leaq 0x94419(%rip), %rcx     # 0x11f288
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x24, %ebx
je 0x8ae8a
cmpl $0x3f, %ebx
je 0x8ae8a
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x8ae95
movw $0x1, (%r14)
callq 0x58682
cmpl $0x3f, %ebx
sete %al
leaq 0x2ad3b0(%rip), %rcx    # 0x338252
xorl %edx, %edx
movw %dx, (%rcx)
leaq 0x2ad3a6(%rip), %rcx    # 0x338254
movw %dx, (%rcx)
movb %dl, 0x2e1bfd(%rip)     # 0x36cab4
movb %dl, 0x2e1bf8(%rip)     # 0x36cab5
movb %dl, 0x2e6fcd(%rip)     # 0x371e90
leal -0x30(%rbx), %ecx
cmpl $0xa, %ecx
setb %cl
orb %al, %cl
je 0x8af65
cmpl $0xa, %ebx
je 0x8af09
cmpl $0xd, %ebx
je 0x8af09
cmpl $0x2a, %ebx
jne 0x8af6e
movw $0x2, (%r14)
jmp 0x8afd2
popq %rbx
popq %r14
popq %rbp
jmp 0x1e6a0
cmpl $0xa, %ebx
je 0x8af09
cmpl $0xd, %ebx
jne 0x8afd7
cmpb $0x1, 0x2e6f80(%rip)    # 0x371e90
jne 0x8af44
leaq 0x2ac337(%rip), %rdi    # 0x337250
leaq 0x987ca(%rip), %rsi     # 0x1236ea
callq 0x9090
testq %rax, %rax
jne 0x8af44
cmpw $0x2, (%r14)
jne 0x8af44
movb 0x2e1b7d(%rip), %al     # 0x36cab4
movl $0x4000, %edx           # imm = 0x4000
cmpb 0x2e1b73(%rip), %al     # 0x36cab5
jne 0x8afa3
callq 0x8ac70
movl $0x1, 0x2e0d41(%rip)    # 0x36bc94
leaq 0x2ad2f8(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
jmp 0x8afc8
movb $0x1, 0x2e6f24(%rip)    # 0x371e90
jmp 0x8afd2
leaq 0x2ad2dd(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
movl $0x8000, %edx           # imm = 0x8000
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x8afa3
xorb %bl, 0x2e1b29(%rip)     # 0x36cab4
leaq 0x1(%rax), %rdx
movw %dx, (%rcx)
leaq 0x2ac2b7(%rip), %rcx    # 0x337250
movb %bl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
jmp 0x8afd2
leaq 0x1b3fc6(%rip), %rax    # 0x23ef70
orl %edx, (%rax)
leaq 0x2ad29f(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
movb %cl, 0x2e1af3(%rip)     # 0x36cab5
movb %cl, 0x2e1aec(%rip)     # 0x36cab4
movl $0x0, 0x2e1b12(%rip)    # 0x36cae4
popq %rbx
popq %r14
popq %rbp
retq
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x8aff1
movzbl 0x2e1acf(%rip), %eax    # 0x36cab5
shll $0x4, %eax
addl $0xd0, %ebx
jmp 0x8b009
leal -0x41(%rbx), %eax
cmpl $0x5, %eax
ja 0x8afac
movzbl 0x2e1ab5(%rip), %eax    # 0x36cab5
shll $0x4, %eax
addl $0xc9, %ebx
orl %eax, %ebx
movb %bl, 0x2e1aa4(%rip)     # 0x36cab5
jmp 0x8afd2