// File: 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
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xbdbd6
movl $0xa, %edi
callq 0x2b610
jmp 0xbdef4
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x2af8d1(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xbdc06
leaq 0x2af8c1(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2d9829(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xbdca6
movzbl -0x1(%rbp), %eax
cmpl $0x24, %eax
je 0xbdc39
movzbl -0x1(%rbp), %eax
cmpl $0x3f, %eax
je 0xbdc39
movzbl -0x1(%rbp), %edi
callq 0x9330
cmpl $0x0, %eax
je 0xbdc4a
leaq 0x2d97f6(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
leaq 0x2d97e1(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2d97d7(%rip), %rax    # 0x397434
movw $0x0, (%rax)
movb $0x0, 0x30e02b(%rip)    # 0x3cbc94
movb $0x0, 0x30e025(%rip)    # 0x3cbc95
movl $0x0, 0x3133fa(%rip)    # 0x3d1074
movzbl -0x1(%rbp), %edi
callq 0x9330
cmpl $0x0, %eax
je 0xbdc8a
jmp 0xbdcbb
movzbl -0x1(%rbp), %eax
cmpl $0x3f, %eax
jne 0xbdc95
jmp 0xbdcbb
jmp 0xbdc97
movl $0x1, 0x3133d3(%rip)    # 0x3d1074
jmp 0xbdef4
leaq 0x2d9789(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xbdd7a
jmp 0xbdcbb
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
je 0xbdccd
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xbdcd2
jmp 0xbde1b
movzbl -0x1(%rbp), %eax
cmpl $0x2a, %eax
jne 0xbdcec
leaq 0x2d9754(%rip), %rax    # 0x397436
movw $0x2, (%rax)
jmp 0xbdd75
leaq 0x2d973f(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xbdd56
movzbl -0x1(%rbp), %ecx
movzbl 0x30df8c(%rip), %eax    # 0x3cbc94
xorl %ecx, %eax
movb %al, 0x30df84(%rip)     # 0x3cbc94
movb -0x1(%rbp), %dl
leaq 0x2d9718(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2d9707(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2d86f6(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2d96ee(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2d86e0(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xbdd73
leaq 0x1e03f3(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1e03e4(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xbdebe
jmp 0xbdd75
jmp 0xbdef2
leaq 0x2d96b5(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xbde06
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
je 0xbdd9b
movzbl -0x1(%rbp), %eax
cmpl $0xa, %eax
jne 0xbdd9d
jmp 0xbde1b
movzbl -0x1(%rbp), %eax
cmpl $0x30, %eax
jl 0xbddca
movzbl -0x1(%rbp), %eax
cmpl $0x39, %eax
jg 0xbddca
movzbl 0x30dedf(%rip), %eax    # 0x3cbc95
shll $0x4, %eax
movzbl -0x1(%rbp), %ecx
subl $0x30, %ecx
orl %ecx, %eax
movb %al, 0x30decd(%rip)     # 0x3cbc95
jmp 0xbde01
movzbl -0x1(%rbp), %eax
cmpl $0x41, %eax
jl 0xbddfa
movzbl -0x1(%rbp), %eax
cmpl $0x46, %eax
jg 0xbddfa
movzbl 0x30deb2(%rip), %eax    # 0x3cbc95
shll $0x4, %eax
movzbl -0x1(%rbp), %ecx
subl $0x41, %ecx
addl $0xa, %ecx
orl %ecx, %eax
movb %al, 0x30de9d(%rip)     # 0x3cbc95
jmp 0xbddff
jmp 0xbdebe
jmp 0xbde01
jmp 0xbdef0
leaq 0x2d9629(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x3, %eax
jne 0xbdebc
jmp 0xbde1b
cmpl $0x0, 0x313252(%rip)    # 0x3d1074
jne 0xbde26
jmp 0xbde89
leaq 0x2d8603(%rip), %rdi    # 0x396430
leaq 0xc8c7d(%rip), %rsi     # 0x186ab1
callq 0x9090
cmpq $0x0, %rax
je 0xbde41
jmp 0xbde87
cmpl $0x0, 0x31322c(%rip)    # 0x3d1074
je 0xbde85
leaq 0x2d95e5(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xbde85
movzbl 0x30de34(%rip), %eax    # 0x3cbc94
movzbl 0x30de2e(%rip), %ecx    # 0x3cbc95
cmpl %ecx, %eax
je 0xbde85
leaq 0x1e02de(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
leaq 0x1e02cf(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xbdebe
jmp 0xbde87
jmp 0xbde89
callq 0xbd9a0
movl $0x1, 0x30cfdc(%rip)    # 0x3cae74
leaq 0x2d9593(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2d958b(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movl $0x0, 0x30de0a(%rip)    # 0x3cbcc4
jmp 0xbdeee
jmp 0xbdebe
leaq 0x2d956d(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2d9565(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movb $0x0, 0x30ddb8(%rip)    # 0x3cbc95
movb $0x0, 0x30ddb0(%rip)    # 0x3cbc94
movl $0x0, 0x30ddd6(%rip)    # 0x3cbcc4
jmp 0xbdef0
jmp 0xbdef2
jmp 0xbdef4
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)