// File: /workspace/github_cpp_makefile_star2_O3/jkingan[P]ladyheather/heathgps.cpp
// Function: get_rt17_message()
void get_rt17_message()
{
u08 c;
static int status;
static int msg;
static int len, xlen;

   // This routine buffers up an incoming RT17 message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_rt17_msg()
   // Some RT17 messages are spread out over several packets.  decode_rt17_msg()
   // re-assembles them into one large packet for parsing.

   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 '$'
      if(c == 0x02) {
         tsip_sync = 1;
         get_sync_time();
      }
      else if(c == 0x06) {  // ack
if(debug_file) fprintf(debug_file, "ack\n");
      }
      else if(c == 0x15) {  // nak
if(debug_file) fprintf(debug_file, "nak\n");
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      rt17_vfy_cksum = 0;  // the calculated message checksum
      rt17_msg_cksum = 0;  // the checksum in the message
      return;
   } 
   else if(tsip_sync == 1) { // STX has been seen, get status byte
      status = c;
      rt17_vfy_cksum += c;
      tsip_sync = 2;
   }
   else if(tsip_sync == 2) {  // msg type byte
      msg = c;
      rt17_vfy_cksum += c;
      tsip_sync = 3;
   }
   else if(tsip_sync == 3) {  // msg len
      len = xlen = c;
      rt17_vfy_cksum += c;
      tsip_sync = 4;
      if(len == 0) {      // null message
         tsip_sync = 5;
      }
   }
   else if(tsip_sync == 4) {  // message data
      rt17_vfy_cksum += c;
      rt17_buf[tsip_wptr++] = c;
      --len;
      if(len == 0) tsip_sync = 5;
   }
   else if(tsip_sync == 5) {  // checksum
      rt17_msg_cksum = c;
      tsip_sync = 6;
   }
   else if(tsip_sync == 6) {  // end of message
sprintf(out, "msg:%02X:%02X:%02X  status:%02X  len:%02x  etx:%02X  chk:%02X  vfy:%02X", 
msg,rt17_buf[0],rt17_buf[1],  status, xlen, c, rt17_msg_cksum&0xFF, rt17_vfy_cksum&0xFF);
if(debug_file) fprintf(debug_file, "%s\n", out);
      if(c != 0x03) goto rst_msg;  // ETX was expected

      rt17_msg_cksum &= 0xFF;
      rt17_vfy_cksum &= 0xFF;
      if(rt17_vfy_cksum != rt17_msg_cksum) goto rst_msg;  // checksums dont match

      decode_rt17_msg(msg, status);  // message checksum matches, process the message
      packet_end = 1;

      tsip_wptr = 0;     // prepare for next message
      tsip_sync = 0;
   }
   else {     // should never happen, prepare for next message
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
      rt17_wptr = 0;
      rt17_vfy_cksum = rt17_msg_cksum = 0; // init received message checksum
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x80e14
callq 0x1ea0b
callq 0x584bd
movl %eax, %ebx
leaq 0x28d526(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0x80dca
movb $0x0, 0x17a12(%rax)
leaq 0x2b7485(%rip), %r14    # 0x338256
movzwl (%r14), %eax
cmpq $0x6, %rax
ja 0x80f77
leaq 0x9e336(%rip), %rcx     # 0x11f11c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $0x6, %bl
je 0x80f9f
movzbl %bl, %eax
cmpl $0x2, %eax
jne 0x80fb7
movw $0x1, (%r14)
callq 0x58672
jmp 0x80fea
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1e66a
addb %bl, 0x2ebc95(%rip)     # 0x36cabe
leaq 0x2b7422(%rip), %rax    # 0x338252
movzwl (%rax), %ecx
leal 0x1(%rcx), %edx
movw %dx, (%rax)
leaq 0x2effc0(%rip), %rax    # 0x370e00
movb %bl, (%rcx,%rax)
decl 0x2f0fd3(%rip)          # 0x371e1c
jne 0x8100c
movw $0x5, (%r14)
jmp 0x8100c
movl %ebx, 0x2f0fb8(%rip)    # 0x371e18
addb %bl, 0x2ebc58(%rip)     # 0x36cabe
movw $0x3, (%r14)
jmp 0x8100c
movl %ebx, 0x2f0fa9(%rip)    # 0x371e20
movl %ebx, 0x2f0f9f(%rip)    # 0x371e1c
addb %bl, 0x2ebc3b(%rip)     # 0x36cabe
xorl %eax, %eax
cmpl $0x1, %ebx
adcw $0x4, %ax
movw %ax, (%r14)
jmp 0x8100c
movl %ebx, 0x2f0f79(%rip)    # 0x371e14
addb %bl, 0x2ebc1d(%rip)     # 0x36cabe
movw $0x2, (%r14)
jmp 0x8100c
movb %bl, 0x2ebc0d(%rip)     # 0x36cabf
movw $0x6, (%r14)
jmp 0x8100c
movl 0x2f0f55(%rip), %edx    # 0x371e18
movzbl 0x2eff36(%rip), %ecx    # 0x370e00
movzbl 0x2eff2f(%rip), %r8d    # 0x370e01
movl 0x2f0f3b(%rip), %r9d    # 0x371e14
movl 0x2f0f40(%rip), %r10d   # 0x371e20
movzbl 0x2ebbd7(%rip), %r11d   # 0x36cabf
movzbl 0x2ebbce(%rip), %r15d   # 0x36cabe
leaq 0x2bb329(%rip), %rdi    # 0x33c220
leaq 0xa1f2a(%rip), %rsi     # 0x122e28
xorl %eax, %eax
pushq %r15
pushq %r11
pushq %rbx
pushq %r10
callq 0x9060
addq $0x20, %rsp
leaq 0x1bd479(%rip), %rax    # 0x23e390
movq (%rax), %rdi
testq %rdi, %rdi
je 0x80f34
leaq 0xa4bb1(%rip), %rsi     # 0x125ad7
leaq 0x2bb2f3(%rip), %rdx    # 0x33c220
xorl %eax, %eax
callq 0x9560
cmpl $0x3, %ebx
jne 0x80f77
movb 0x2ebb7f(%rip), %al     # 0x36cabe
cmpb 0x2ebb7a(%rip), %al     # 0x36cabf
jne 0x80f77
movl 0x2f0ecb(%rip), %edi    # 0x371e18
movl 0x2f0ec1(%rip), %esi    # 0x371e14
callq 0x80a37
movl $0x1, 0x2ead32(%rip)    # 0x36bc94
leaq 0x2b72e9(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
jmp 0x8100c
leaq 0x2b72d4(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
movl $0x0, 0x2f0e6f(%rip)    # 0x371e00
movb %cl, 0x2ebb28(%rip)     # 0x36cabf
movb %cl, 0x2ebb21(%rip)     # 0x36cabe
jmp 0x8100c
leaq 0x1bd3ea(%rip), %rax    # 0x23e390
movq (%rax), %rcx
testq %rcx, %rcx
je 0x80fea
leaq 0xa1e69(%rip), %rdi     # 0x122e1e
jmp 0x80fdb
cmpl $0x15, %ebx
sete %al
leaq 0x1bd3cc(%rip), %rcx    # 0x23e390
movq (%rcx), %rcx
testq %rcx, %rcx
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x80fea
leaq 0xa1e48(%rip), %rdi     # 0x122e23
movl $0x4, %esi
movl $0x1, %edx
callq 0x9750
leaq 0x2b7261(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x2b7257(%rip), %rax    # 0x338254
movw %cx, (%rax)
movb %cl, 0x2ebab8(%rip)     # 0x36cabe
movb %cl, 0x2ebab3(%rip)     # 0x36cabf
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq