// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x89968
callq 0x1ea0b
callq 0x584bd
leaq 0x2849c8(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x89928
movb $0x0, 0x17a12(%rcx)
leaq 0x2ae927(%rip), %r15    # 0x338256
movzwl (%r15), %ecx
cmpq $0x3, %rcx
ja 0x89b32
leaq 0x95994(%rip), %rdx     # 0x11f2d8
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpb $0x10, %al
je 0x89abf
movzbl %al, %eax
cmpl $0x3a, %eax
jne 0x89ad2
movb $0x1, %bl
jmp 0x89ac1
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1e66a
cmpl $0xd, %eax
jne 0x89a64
testb $0x1, 0x2e84ff(%rip)    # 0x371e88
je 0x89a64
movw $0x3, (%r15)
leaq 0x2ae8b6(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xffe, %rax            # imm = 0xFFE
ja 0x89b32
leal 0x1(%rax), %edx
movw %dx, (%rcx)
leaq 0x2ad898(%rip), %rcx    # 0x337250
movw $0x0, (%rcx,%rax)
jmp 0x89b42
cmpb $0x1, 0x2e84be(%rip)    # 0x371e88
jne 0x89a74
movb $0x0, 0x2e30dd(%rip)    # 0x36cab4
movq $-0x2, %r12
leaq 0x2ad86b(%rip), %rbx    # 0x337250
leaq -0x23(%rbp), %r14
movzwl 0x2(%rbx,%r12), %eax
movw %ax, -0x23(%rbp)
movb $0x0, -0x21(%rbp)
movq %r14, %rdi
callq 0x98c6
addb %al, 0x2e30af(%rip)     # 0x36cab4
addq $0x2, %r12
cmpq $0x14, %r12
jb 0x899e9
addq $0x16, %rbx
movq %rbx, %rdi
callq 0x98c6
cmpb %al, 0x2e3093(%rip)     # 0x36cab4
jne 0x89b32
callq 0x8925f
jmp 0x89b32
cmpb $0x3, %al
je 0x89b32
movzbl %al, %ecx
cmpl $0x10, %ecx
je 0x89b32
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x30, %ecx
je 0x89a5c
testb $0x1, 0x2e8432(%rip)    # 0x371e88
jne 0x89b32
movw $0x2, (%r15)
jmp 0x89a8d
cmpl $0x10, %eax
jne 0x89a8d
movw $0x3, (%r15)
jmp 0x89b42
cmpl $0x3, %eax
jne 0x89af6
callq 0x89605
movl $0x1, 0x2e220c(%rip)    # 0x36bc94
jmp 0x89b32
leaq 0x2ae7be(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x89b27
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2ad79e(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
jmp 0x89b42
xorl %ebx, %ebx
movw $0x1, (%r15)
callq 0x58672
movb %bl, 0x2e83b6(%rip)     # 0x371e88
xorl %eax, %eax
movb %al, 0x2e2fda(%rip)     # 0x36cab4
movb %al, 0x2e2fd5(%rip)     # 0x36cab5
leaq 0x2ae76b(%rip), %rcx    # 0x338252
movw %ax, (%rcx)
leaq 0x2ae763(%rip), %rcx    # 0x338254
movw %ax, (%rcx)
jmp 0x89b42
leaq 0x2ae755(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xffe, %rcx            # imm = 0xFFE
ja 0x89b27
leaq 0x1(%rcx), %rsi
movw %si, (%rdx)
leaq 0x2ad739(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
movb $0x0, 0x1(%rdx,%rcx)
movw $0x2, (%r15)
jmp 0x89b42
leaq 0x1b5442(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
leaq 0x2ae719(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r15)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq