// File: /workspace/github_cpp_makefile_star2_O3/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 %r14
pushq %rbx
movl $0xa, %edi
callq 0xb9ad
movl $0xa, %edi
testl %eax, %eax
je 0x9d5bb
callq 0x1ea0b
callq 0x584bd
movl %eax, %ebx
leaq 0x270d98(%rip), %rax    # 0x30e2e0
cmpb $0x0, 0x17a12(%rax)
je 0x9d558
movb $0x0, 0x17a12(%rax)
leaq 0x29acf7(%rip), %r14    # 0x338256
movzwl (%r14), %eax
cmpq $0x9, %rax
ja 0x9d743
leaq 0x823a0(%rip), %rcx     # 0x11f914
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x40, %ebx
jne 0x9d58d
movw $0x1, (%r14)
callq 0x58672
leaq 0x29acbe(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
leaq 0x29acb4(%rip), %rax    # 0x338254
movw %cx, (%rax)
movl %ecx, 0x2cf51b(%rip)    # 0x36cac4
movl %ecx, 0x2cf519(%rip)    # 0x36cac8
movb $0x0, 0x2cf50b(%rip)    # 0x36cac1
jmp 0x9d753
popq %rbx
popq %r14
popq %rbp
jmp 0x1e66a
leaq 0x29ac87(%rip), %rcx    # 0x338252
movzwl (%rcx), %eax
cmpq $0xfff, %rax            # imm = 0xFFF
ja 0x9d723
xorb %bl, 0x2cf4e1(%rip)     # 0x36cac1
leal 0x1(%rax), %edx
movw %dx, (%rcx)
leaq 0x299c63(%rip), %rcx    # 0x337250
movb %bl, (%rcx,%rax)
movl 0x2cf4ce(%rip), %eax    # 0x36cac4
leal -0x1(%rax), %ecx
movl %ecx, 0x2cf4c5(%rip)    # 0x36cac4
cmpl $0x2, %eax
jge 0x9d753
movw $0x5, (%r14)
jmp 0x9d753
movl 0x2d48a7(%rip), %edi    # 0x371ec0
movl 0x2d48a5(%rip), %esi    # 0x371ec4
callq 0x9ce4d
movl $0x1, 0x2ce666(%rip)    # 0x36bc94
movw $0x0, (%r14)
jmp 0x9d753
movl %ebx, %eax
addl $-0x41, %eax
cmpl $0x19, %eax
ja 0x9d743
movl %ebx, 0x2d4873(%rip)    # 0x371ec0
xorb %bl, 0x2cf46e(%rip)     # 0x36cac1
movw $0x3, (%r14)
jmp 0x9d753
movl %ebx, %edi
callq 0x9580
addl $-0x61, %eax
cmpl $0x19, %eax
ja 0x9d743
movl %ebx, 0x2d484d(%rip)    # 0x371ec4
xorb %bl, 0x2cf444(%rip)     # 0x36cac1
movl 0x2d483d(%rip), %edi    # 0x371ec0
movl %ebx, %esi
callq 0x9c8e2
movl %eax, 0x2cf434(%rip)    # 0x36cac4
movl %eax, 0x2cf432(%rip)    # 0x36cac8
testl %eax, %eax
js 0x9d743
xorl %ecx, %ecx
cmpl $0x1, %eax
adcw $0x4, %cx
jmp 0x9d74f
movl 0x2d4816(%rip), %eax    # 0x371ec8
leal (%rax,%rax,4), %eax
leal (%rbx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0x2d4807(%rip)    # 0x371ec8
movzbl 0x2cf3f9(%rip), %ecx    # 0x36cac1
cmpl %ecx, %eax
je 0x9d73b
jmp 0x9d743
cmpl $0x40, %ebx
jne 0x9d743
movw $0x2, (%r14)
jmp 0x9d753
cmpl $0x45, 0x2d47de(%rip)   # 0x371ec0
jne 0x9d730
cmpl $0x71, 0x2d47d9(%rip)   # 0x371ec4
jne 0x9d730
addl $-0x30, %ebx
movl %ebx, 0x2d47d2(%rip)    # 0x371ec8
movw $0x6, (%r14)
jmp 0x9d753
movl 0x2d47c4(%rip), %eax    # 0x371ec8
leal (%rax,%rax,4), %eax
leal (%rbx,%rax,2), %eax
addl $-0x30, %eax
movl %eax, 0x2d47b5(%rip)    # 0x371ec8
movw $0x7, (%r14)
jmp 0x9d753
movw $0x9, (%r14)
jmp 0x9d753
leaq 0x1a1846(%rip), %rax    # 0x23ef70
orb $-0x80, 0x1(%rax)
jmp 0x9d743
movzbl 0x2cf38a(%rip), %eax    # 0x36cac1
cmpl %eax, %ebx
jne 0x9d743
movw $0x8, (%r14)
jmp 0x9d753
leaq 0x29ab08(%rip), %rax    # 0x338252
xorl %ecx, %ecx
movw %cx, (%rax)
movw %cx, (%r14)
popq %rbx
popq %r14
popq %rbp
retq