// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_tm4_message()
void get_tm4_message()
{
u08 c;

   // This routine buffers up an incoming Spectrum TM4 message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_nmea_msg()

   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;
      return;
   }
   else if(tsip_sync == 1) { // '#' has been seen, now build the message
      if(c == 0x0D) {
         tsip_sync = 2;
         return;
      }

      if(tsip_wptr < MAX_TSIP) {   // add char to the message buffer
         tsip_buf[tsip_wptr++] = c;
         tsip_buf[tsip_wptr] = 0;
      }
      else {
         tsip_error |= OVFL_ERROR;
         goto rst_msg;
      }
   }
   else if(tsip_sync == 2) {  // 0x0A end of message
      decode_tm4_msg(); 
      packet_end = 1;
      tsip_wptr = 0;     // prepare for next message
      tsip_rptr = 0;
      tsip_sync = 0;
   }
   else {     // should never happen, prepare for next message
      rst_msg:
      tsip_wptr = 0;
      tsip_rptr = 0;
      tsip_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xe0dd6
movl $0xa, %edi
callq 0x2b610
jmp 0xe0f5a
movl $0xa, %edi
callq 0x2bd30
callq 0x79fc0
movb %al, -0x1(%rbp)
leaq 0x28c6d1(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xe0e06
leaq 0x28c6c1(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
leaq 0x2b6629(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xe0e4c
movzbl -0x1(%rbp), %eax
cmpl $0x23, %eax
jne 0xe0e2f
leaq 0x2b6611(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
leaq 0x2b65fc(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b65f2(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xe0f5a
leaq 0x2b65e3(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xe0eec
movzbl -0x1(%rbp), %eax
cmpl $0xd, %eax
jne 0xe0e79
leaq 0x2b65c7(%rip), %rax    # 0x397436
movw $0x2, (%rax)
jmp 0xe0f5a
leaq 0x2b65b2(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0x1000, %eax           # imm = 0x1000
jge 0xe0ed0
movb -0x1(%rbp), %dl
leaq 0x2b659e(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2b658d(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2b557c(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2b6574(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2b5566(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xe0eea
leaq 0x1bd279(%rip), %rax    # 0x29e150
movl (%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
leaq 0x1bd26a(%rip), %rax    # 0x29e150
movl %ecx, (%rax)
jmp 0xe0f32
jmp 0xe0f58
leaq 0x2b6543(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xe0f30
callq 0xe0890
movl $0x1, 0x2e9f6a(%rip)    # 0x3cae74
leaq 0x2b6521(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b6517(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2b650d(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xe0f56
jmp 0xe0f32
leaq 0x2b64f9(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2b64ef(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2b64e5(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xe0f58
jmp 0xe0f5a
addq $0x10, %rsp
popq %rbp
retq