// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x7e3aa
callq 0x1d93f
callq 0x51891
movl %eax, %ebx
leaq 0x279ff1(%rip), %rax    # 0x2f82e0
cmpb $0x0, 0x17a12(%rax)
je 0x7e2ff
movb $0x0, 0x17a12(%rax)
leaq 0x2a3f50(%rip), %r14    # 0x322256
movzwl (%r14), %eax
cmpq $0x3, %rax
ja 0x7e467
leaq 0x8af71(%rip), %rcx     # 0x10928c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x24, %bl
je 0x7e33d
movzbl %bl, %eax
cmpl $0x3f, %eax
je 0x7e33d
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x7e4ab
movw $0x1, (%r14)
callq 0x51a2f
leal -0x30(%rbx), %eax
cmpl $0xa, %eax
setb %al
cmpl $0x3f, %ebx
sete %cl
leaq 0x2a3ef4(%rip), %rdx    # 0x322252
andw $0x0, (%rdx)
leaq 0x2a3eeb(%rip), %rdx    # 0x322254
andw $0x0, (%rdx)
xorl %edx, %edx
movb %dl, 0x2d873f(%rip)     # 0x356ab4
movb %dl, 0x2d873a(%rip)     # 0x356ab5
movb %dl, 0x2ddb0f(%rip)     # 0x35be90
orb %al, %cl
je 0x7e420
cmpb $0xa, %bl
je 0x7e3c4
movzbl %bl, %eax
cmpl $0xd, %eax
je 0x7e3c4
cmpl $0x2a, %eax
jne 0x7e429
movw $0x2, (%r14)
jmp 0x7e48c
popq %rbx
popq %r14
popq %rbp
jmp 0x1d61b
cmpb $0xa, %bl
je 0x7e3c4
movzbl %bl, %eax
cmpl $0xd, %eax
jne 0x7e491
cmpb $0x1, 0x2ddac5(%rip)    # 0x35be90
jne 0x7e3ff
leaq 0x2a2e7c(%rip), %rdi    # 0x321250
leaq 0x8f337(%rip), %rsi     # 0x10d712
callq 0x9090
testq %rax, %rax
jne 0x7e3ff
cmpw $0x2, (%r14)
jne 0x7e3ff
movb 0x2d86c2(%rip), %al     # 0x356ab4
movl $0x4000, %edx           # imm = 0x4000
cmpb 0x2d86b8(%rip), %al     # 0x356ab5
jne 0x7e45e
callq 0x7e10e
leaq 0x2a3e47(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%r14)
movl $0x1, 0x2d7876(%rip)    # 0x355c94
jmp 0x7e485
movb $0x1, 0x2dda69(%rip)    # 0x35be90
jmp 0x7e48c
leaq 0x2a3e22(%rip), %rcx    # 0x322252
movzwl (%rcx), %eax
movl $0x8000, %edx           # imm = 0x8000
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x7e45e
xorb %bl, 0x2d866e(%rip)     # 0x356ab4
leaq 0x1(%rax), %rdx
movw %dx, (%rcx)
leaq 0x2a2dfc(%rip), %rcx    # 0x321250
movb %bl, (%rcx,%rax)
movb $0x0, 0x1(%rcx,%rax)
jmp 0x7e48c
leaq 0x1aab0b(%rip), %rax    # 0x228f70
orl %edx, (%rax)
leaq 0x2a3de4(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%r14)
xorl %eax, %eax
movb %al, 0x2d8636(%rip)     # 0x356ab5
movb %al, 0x2d862f(%rip)     # 0x356ab4
andl $0x0, 0x2d8658(%rip)    # 0x356ae4
popq %rbx
popq %r14
popq %rbp
retq
leal -0x30(%rbx), %eax
cmpl $0x9, %eax
ja 0x7e4b2
movzbl 0x2d8615(%rip), %eax    # 0x356ab5
shll $0x4, %eax
addl $0xd0, %ebx
jmp 0x7e4ca
xorl %eax, %eax
jmp 0x7e351
leal -0x41(%rbx), %eax
cmpl $0x5, %eax
ja 0x7e467
movzbl 0x2d85f4(%rip), %eax    # 0x356ab5
shll $0x4, %eax
addl $0xc9, %ebx
orl %eax, %ebx
movb %bl, 0x2d85e3(%rip)     # 0x356ab5
jmp 0x7e48c