// File: /workspace/github_cpp_makefile_star2_O1/jkingan[P]ladyheather/heathgps.cpp
// Function: get_moto_message()
void get_moto_message()
{
u08 c;
static int cmd1 = 0;
static int cmd2 = 0;
static int eq_cksum = 0; // ascii Eq message checksum

   // this routine buffers up an incoming Motorola binary message

   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 == '@') {
         tsip_sync = 1;
         get_sync_time();
      }
      tsip_wptr = 0;
      tsip_rptr = 0;
      moto_msg_len = moto_msg_ptr = 0;
      moto_vfy_cksum = 0;
      return;
   }
   else if(tsip_sync == 1) {    // @ had been seen, now check next byte for '@'
      if(c != '@') goto rst_msg;
      ++tsip_sync;
   }
   else if(tsip_sync == 2) {    // get first byte of command
      if((c >= 'A') && (c <= 'Z')) {
         cmd1 = c;
         moto_vfy_cksum ^= c;
         ++tsip_sync;
      }
      else goto rst_msg;
   }
   else if(tsip_sync == 3) {   // next byte of command
      if((tolower(c) >= 'a') && (tolower(c) <= 'z')) {
         cmd2 = c;
         moto_vfy_cksum ^= c;
         moto_msg_len = moto_msg_ptr = find_moto_cmd(cmd1, cmd2);
         if(moto_msg_len < 0) goto rst_msg;       // unknown command
         else if(moto_msg_len == 0) ++tsip_sync;  // no payload bytes
      }
      else goto rst_msg;
      ++tsip_sync;
   }
   else if(tsip_sync == 4) {   // buffer up message bytes
      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         moto_vfy_cksum ^= c;
         tsip_buf[tsip_wptr++] = c;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
      if(--moto_msg_ptr <= 0) ++tsip_sync;  // end of message payload
   }
   else if(tsip_sync == 5) {   // get checksum and verify, parse payload
      if((cmd1 == 'E') && (cmd2 == 'q')) {  // BASTARD ASCII message format
         eq_cksum = (c - '0');
         ++tsip_sync;
      }
      else {
         if(c != moto_vfy_cksum) goto rst_msg;
         tsip_sync = 8;  // get 0x0D 0x0A
         if(0) {
            decode_moto_msg(cmd1, cmd2);
            packet_end = 1;
            tsip_sync = 0;
         }
      }
   }
   else if(tsip_sync == 6) {  // second byte of ascii checksum - ascii posn msg
      eq_cksum = (eq_cksum*10) + (c - '0');
      ++tsip_sync;
   }
   else if(tsip_sync == 7) {  // final byte of ascii checksum - ascii posn msg
      eq_cksum = (eq_cksum*10) + (c - '0');
//sprintf(plot_title, "c:%c eq:%d vfy:%d", c, eq_cksum, moto_vfy_cksum);
      if(eq_cksum != moto_vfy_cksum) goto rst_msg;
      tsip_sync = 8;  // get 0x0A 0x0A
      if(0) {
         decode_moto_msg(cmd1, cmd2);
         packet_end = 1;
         tsip_sync = 0;
      }
   }
   else if(tsip_sync == 8) {  // 0x0D
      tsip_sync = 9;
   }
   else if(tsip_sync == 9) {  // 0x0A
      decode_moto_msg(cmd1, cmd2);
      packet_end = 1;
      tsip_sync = 0;
   }
   else {
      rst_msg:
      tsip_wptr = 0;
      tsip_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl $0xa, %edi
callq 0xb9c3
movl $0xa, %edi
testl %eax, %eax
je 0x9d3dd
callq 0x1ea2c
callq 0x584d5
movl %eax, %ebx
leaq 0x270f76(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0x9d37a
movb $0x0, 0x17a12(%rax)
leaq 0x29aed5(%rip), %r14    # 0x338256
movzwl (%r14), %r15d
cmpq $0x9, %r15
ja 0x9d55a
leaq 0x824a6(%rip), %rax     # 0x11f83c
movslq (%rax,%r15,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpl $0x40, %ebx
jne 0x9d3af
movw $0x1, (%r14)
callq 0x58682
leaq 0x29ae9c(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x29ae92(%rip), %rax    # 0x338254
movw %cx, (%rax)
movl %ecx, 0x2cf6f9(%rip)    # 0x36cac4
movl %ecx, 0x2cf6f7(%rip)    # 0x36cac8
movb $0x0, 0x2cf6e9(%rip)    # 0x36cac1
jmp 0x9d56a
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1e6a0
leaq 0x29ae5f(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x9d53a
xorb %bl, 0x2cf6b9(%rip)     # 0x36cac1
leal 0x1(%rax), %edx
movw %dx, (%rcx)
leaq 0x299e3b(%rip), %rcx    # 0x337250
movb %bl, (%rcx,%rax)
movl 0x2cf6a6(%rip), %eax    # 0x36cac4
leal -0x1(%rax), %ecx
movl %ecx, 0x2cf69d(%rip)    # 0x36cac4
cmpl $0x2, %eax
jl 0x9d528
jmp 0x9d56a
movl 0x2d4a85(%rip), %edi    # 0x371ec0
movl 0x2d4a83(%rip), %esi    # 0x371ec4
callq 0x9cc6c
movl $0x1, 0x2ce844(%rip)    # 0x36bc94
movw $0x0, (%r14)
jmp 0x9d56a
movl %ebx, %eax
addl $-0x41, %eax
cmpl $0x19, %eax
ja 0x9d55a
xorb %bl, 0x2cf652(%rip)     # 0x36cac1
movl %ebx, 0x2d4a4b(%rip)    # 0x371ec0
jmp 0x9d528
movl %ebx, %edi
callq 0x9580
addl $-0x61, %eax
cmpl $0x19, %eax
ja 0x9d55a
movl %ebx, 0x2d4a31(%rip)    # 0x371ec4
xorb %bl, 0x2cf628(%rip)     # 0x36cac1
movl 0x2d4a21(%rip), %edi    # 0x371ec0
movl %ebx, %esi
callq 0x9c701
movl %eax, 0x2cf618(%rip)    # 0x36cac4
movl %eax, 0x2cf616(%rip)    # 0x36cac8
testl %eax, %eax
js 0x9d55a
jne 0x9d4c4
leal 0x1(%r15), %eax
movw %ax, (%r14)
incw (%r14)
jmp 0x9d56a
movl 0x2d49f5(%rip), %eax    # 0x371ec8
leal (%rax,%rax,4), %eax
leal (%rbx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0x2d49e6(%rip)    # 0x371ec8
movzbl 0x2cf5d8(%rip), %ecx    # 0x36cac1
cmpl %ecx, %eax
je 0x9d552
jmp 0x9d55a
cmpl $0x40, %ebx
je 0x9d528
jmp 0x9d55a
cmpl $0x45, 0x2d49c3(%rip)   # 0x371ec0
jne 0x9d547
cmpl $0x71, 0x2d49be(%rip)   # 0x371ec4
jne 0x9d547
addl $-0x30, %ebx
movl %ebx, 0x2d49b7(%rip)    # 0x371ec8
jmp 0x9d528
movl 0x2d49af(%rip), %eax    # 0x371ec8
leal (%rax,%rax,4), %eax
leal (%rbx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0x2d49a0(%rip)    # 0x371ec8
leal 0x1(%r15), %eax
movw %ax, (%r14)
jmp 0x9d56a
movw $0x9, (%r14)
jmp 0x9d56a
leaq 0x1a1a2f(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
jmp 0x9d55a
movzbl 0x2cf573(%rip), %eax    # 0x36cac1
cmpl %eax, %ebx
jne 0x9d55a
movw $0x8, (%r14)
jmp 0x9d56a
leaq 0x29acf1(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq