// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0xa
popq %rdi
callq 0xb771
pushq $0xa
popq %rdi
testl %eax, %eax
je 0x74196
callq 0x1d93f
callq 0x51891
leaq 0x2841a5(%rip), %rcx    # 0x2f82e0
cmpb $0x0, 0x17a12(%rcx)
je 0x7414b
movb $0x0, 0x17a12(%rcx)
leaq 0x2ae104(%rip), %rbx    # 0x322256
movzwl (%rbx), %ecx
cmpq $0x3, %rcx
ja 0x741f2
leaq 0x94eca(%rip), %rdx     # 0x109030
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x10, %eax
jne 0x7417e
movw $0x1, (%rbx)
callq 0x51a2f
leaq 0x2ae0cd(%rip), %rax    # 0x322252
andw $0x0, (%rax)
leaq 0x2ae0c4(%rip), %rax    # 0x322254
andw $0x0, (%rax)
jmp 0x74201
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1d61b
cmpl $0x10, %eax
jne 0x74208
movw $0x3, (%rbx)
jmp 0x74201
cmpl $0x3, %eax
jne 0x7422d
callq 0x73e39
movl $0x1, 0x2e1ad3(%rip)    # 0x355c94
jmp 0x741f2
cmpb $0x3, %al
je 0x741f2
movzbl %al, %ecx
cmpl $0x10, %ecx
je 0x741f2
movw $0x2, (%rbx)
leaq 0x2ae077(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
jbe 0x7421b
leaq 0x1b4d82(%rip), %rax    # 0x228f70
orb $-0x80, 0x1(%rax)
leaq 0x2ae059(%rip), %rax    # 0x322252
andw $0x0, (%rax)
andw $0x0, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x2ae043(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x74252
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2ad028(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
jmp 0x74201
leaq 0x2ae01e(%rip), %rdx    # 0x322252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x7425f
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2ad003(%rip), %rdx    # 0x321250
movb %al, (%rdx,%rcx)
jmp 0x7426a
leaq 0x1b4d17(%rip), %rax    # 0x228f70
orb $-0x80, 0x1(%rax)
jmp 0x74201
leaq 0x1b4d0a(%rip), %rax    # 0x228f70
orb $-0x80, 0x1(%rax)
movw $0x2, (%rbx)
jmp 0x74201