// File: /workspace/github_cpp_makefile_star2_O1/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 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x7f8c7
callq 0x1ea2c
callq 0x584d5
leaq 0x28ea74(%rip), %rcx    # 0x30e2e0
cmpb $0x0, 0x17a12(%rcx)
je 0x7f87c
movb $0x0, 0x17a12(%rcx)
leaq 0x2b89d3(%rip), %rbx    # 0x338256
movzwl (%rbx), %ecx
cmpq $0x3, %rcx
ja 0x7f921
leaq 0x9f795(%rip), %rdx     # 0x11f02c
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
cmpl $0x10, %eax
jne 0x7f8af
movw $0x1, (%rbx)
callq 0x58682
leaq 0x2b899c(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2b8992(%rip), %rax    # 0x338254
movw %cx, (%rax)
jmp 0x7f930
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x1e6a0
cmpl $0x10, %eax
jne 0x7f937
movw $0x3, (%rbx)
jmp 0x7f930
cmpl $0x3, %eax
jne 0x7f95c
callq 0x7f504
movl $0x1, 0x2ec3a2(%rip)    # 0x36bc94
jmp 0x7f921
cmpl $0x3, %eax
je 0x7f921
cmpl $0x10, %eax
je 0x7f921
movw $0x2, (%rbx)
leaq 0x2b8948(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
jbe 0x7f94a
leaq 0x1bf653(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
leaq 0x2b892a(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x2b8914(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x7f981
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b78f9(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x7f930
leaq 0x2b88ef(%rip), %rdx    # 0x338252
movzwl (%rdx), %ecx
cmpq $0xfff, %rcx            # imm = 0xFFF
ja 0x7f98e
leal 0x1(%rcx), %esi
movw %si, (%rdx)
leaq 0x2b78d4(%rip), %rdx    # 0x337250
movb %al, (%rdx,%rcx)
jmp 0x7f999
leaq 0x1bf5e8(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
jmp 0x7f930
leaq 0x1bf5db(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
movw $0x2, (%rbx)
jmp 0x7f930