// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_tsip_message()
void get_tsip_message()
{
u08 c;

   // 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();
      }
      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 {                    // DLE xx is message start
         tsip_sync = 2;         // ... so accumulate the message
         if(tsip_wptr < MAX_TSIP) {
            tsip_buf[tsip_wptr++] = c;
         }
         else {                 // buffer overlow
            tsip_error |= OVFL_ERROR;
            goto rst_msg;
         }
      }
   }
   else if(tsip_sync == 2) {    // buffer up the message
      if(c == DLE) tsip_sync = 3;
      else if(tsip_wptr < MAX_TSIP) {
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
////     goto rst_msg;
      }
   }
   else if(tsip_sync == 3) {   // last char was a DLE
      if(c == ETX) {           // DLE ETX is end-of-message
         decode_tsip_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) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = c;
         }
         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 %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x7f6fa
callq 0x1ea0b
callq 0x584bd
leaq 0x28ec41(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x7f6af
movb $0x0, 0x17a12(%rcx)
leaq 0x2b8ba0(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x3, %rcx
ja 0x7f756
leaq 0x9fa22(%rip), %rdx     # 0x11f0ec
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x10, %eax
jne 0x7f6e2
movw $0x1, (%rbx)
callq 0x58672
leaq 0x2b8b69(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2b8b5f(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0x7f765
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e66a
cmpl $0x10, %eax
jne 0x7f76c
movw $0x3, (%rbx)
jmp 0x7f765
cmpl $0x3, %eax
jne 0x7f791
callq 0x7f33f
movl $0x1, 0x2ec56f(%rip)    # 0x36bc94
jmp 0x7f756
cmpb $0x3, %al
je 0x7f756
movzbl %al, %ecx
cmpl $0x10, %ecx
je 0x7f756
movw $0x2, (%rbx)
leaq 0x2b8b13(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
jbe 0x7f77f
leaq 0x1bf81e(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
leaq 0x2b8af5(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x2b8adf(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x7f7b6
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b7ac4(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x7f765
leaq 0x2b8aba(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x7f7c3
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b7a9f(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x7f7ce
leaq 0x1bf7b3(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
jmp 0x7f765
leaq 0x1bf7a6(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
movw $0x2, (%rbx)
jmp 0x7f765