// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: get_rftg_message()
void get_rftg_message()
{
u08 c;
int i;
static int colon = 0;
char s[3];  // used to calculate message cksum

   // this routine buffers up an incoming TSIP message and then parses it
   // when it is complete.

   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 DLE
      if(c == DLE) {
         tsip_sync = 1;
         get_sync_time();
         colon = 0;
      }
      else if(c == ':') {
         tsip_sync = 1;
         get_sync_time();
         colon = 1;
      }

      nmea_vfy_cksum = 0;
      nmea_msg_cksum = 0;
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) {    // DLE had been seen, now checking next byte
      if(c == DLE) {            // DLE DLE is a 0x10 data byte
         goto rst_msg;
      }
      else if(c == ETX) {       // DLE ETX is end-of-message
         goto rst_msg;          // ... should never happen here
      }
      else if(colon) {
         if((c == '0') || (c == '1')) {
            goto get_msg;
         }
         else goto rst_msg;
      }
      else {                    // DLE xx is message start
         get_msg:
         tsip_sync = 2;         // ... so accumulate the message
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {                 // buffer overlow
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
      }
   }
   else if(tsip_sync == 2) {    // buffer up the message
      if(colon && (c == 0x0D)) {
         tsip_sync = 3;
         if(tsip_wptr < (MAX_TSIP-1)) {
            tsip_buf[tsip_wptr++] = 0;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            goto rst_msg;
         }
      }
      else if(c == DLE) {
         tsip_sync = 3;
      }
      else if(tsip_wptr < (MAX_TSIP-1)) {
         tsip_buf[tsip_wptr++] = c;
         tsip_buf[tsip_wptr] = 0;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 3) {   // last char was a DLE
      if(colon) {
         nmea_vfy_cksum = 0;
         for(i=0; i<22; i+=2) {
            s[0] = tsip_buf[i];
            s[1] = tsip_buf[i+1];
            s[2] = 0;
            nmea_vfy_cksum += atohex(s);
         }
         nmea_vfy_cksum &= 0xFF;

         i = atohex((char *) &tsip_buf[22]) & 0xFF;
         if(nmea_vfy_cksum == i) {
            parse_rftg_time();
         }
         goto rst_msg;
      }
      else if(c == ETX) {           // DLE ETX is end-of-message
         decode_rftg_message(); // so process the buffered message
         packet_end = 1;

         rst_msg:
         tsip_wptr = 0;
         tsip_sync = 0;
      }
      else {                   // DLE DLE is a DLE data byte and DLE xx is message ID
         if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = c;
            tsip_buf[tsip_wptr] = 0;
         }
         else {
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
         tsip_sync = 2;
      }
   }
   else {     // should never happen
      goto rst_msg;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x7cfce
callq 0x1d93f
callq 0x51891
leaq 0x27b362(%rip), %rcx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rcx)
je 0x7cf8e
movb $0x0, 0x17a12(%rcx)
leaq 0x2a52c1(%rip), %r15    # 0x322256
movzwl (%r15), %ecx
cmpq $0x3, %rcx
ja 0x7d196
leaq 0x8c272(%rip), %rdx     # 0x10921c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpb $0x10, %al
je 0x7d121
movzbl %al, %eax
cmpl $0x3a, %eax
jne 0x7d134
movb $0x1, %bl
jmp 0x7d123
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1d61b
cmpl $0xd, %eax
jne 0x7d0a4
testb $0x1, 0x2dee99(%rip)    # 0x35be88
je 0x7d0a4
movw $0x3, (%r15)
leaq 0x2a5250(%rip), %rcx    # 0x322252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0x7d196
leal 0x1(%rax), %edx
movw %dx, (%rcx)
leaq 0x2a4232(%rip), %rcx    # 0x321250
andw $0x0, (%rcx,%rax)
jmp 0x7d1a6
cmpb $0x1, 0x2dee59(%rip)    # 0x35be88
jne 0x7d0d6
movb $0x0, 0x2d9a78(%rip)    # 0x356ab4
xorl %r12d, %r12d
leaq 0x2a420a(%rip), %rbx    # 0x321250
leaq -0x23(%rbp), %r14
cmpq $0x15, %r12
ja 0x7d0b4
movzwl (%rbx,%r12), %eax
movw %ax, -0x23(%rbp)
movb $0x0, -0x21(%rbp)
movq %r14, %rdi
callq 0x98b2
addb %al, 0x2d9a49(%rip)     # 0x356ab4
addq $0x2, %r12
jmp 0x7d04a
cmpb $0x3, %al
je 0x7d196
movzbl %al, %ecx
cmpl $0x10, %ecx
je 0x7d196
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x30, %ecx
je 0x7d09c
testb $0x1, 0x2dedf2(%rip)    # 0x35be88
jne 0x7d196
movw $0x2, (%r15)
jmp 0x7d0ef
cmpl $0x10, %eax
jne 0x7d0ef
movw $0x3, (%r15)
jmp 0x7d1a6
addq $0x16, %rbx
movq %rbx, %rdi
callq 0x98b2
cmpb %al, 0x2d99ee(%rip)     # 0x356ab4
jne 0x7d196
callq 0x7ca89
jmp 0x7d196
cmpl $0x3, %eax
jne 0x7d15a
callq 0x7cdd4
movl $0x1, 0x2d8baa(%rip)    # 0x355c94
jmp 0x7d196
leaq 0x2a515c(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x7d18b
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2a413c(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
jmp 0x7d1a6
xorl %ebx, %ebx
movw $0x1, (%r15)
callq 0x51a2f
movb %bl, 0x2ded54(%rip)     # 0x35be88
xorl %eax, %eax
movb %al, 0x2d9978(%rip)     # 0x356ab4
movb %al, 0x2d9973(%rip)     # 0x356ab5
leaq 0x2a5109(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x2a5100(%rip), %rax    # 0x322254
andw $0x0, (%rax)
jmp 0x7d1a6
leaq 0x2a50f1(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x7d18b
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2a40d5(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
movw $0x2, (%r15)
jmp 0x7d1a6
leaq 0x1abdde(%rip), %rax    # 0x228f70
orb $-0x80, 0x1(%rax)
leaq 0x2a50b5(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq