// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heathgps.cpp
// Function: get_dac_message(unsigned int)
void get_dac_message(unsigned port)
{
u08 c;
static u08 last_c = 0;

   // This routine buffers up an incoming ADC message.  When the end of the
   // message is seen, the message is parsed and decoded with decode_dac_msg()
   // Messages can end with 0x0D, 0x0A, or both.

   if(SERIAL_DATA_AVAILABLE(port) == 0) {
      check_com_timer(port);
      return;
   }
   else {
      reset_com_timer(port);
   }

   if(port == RCVR_PORT) {  // ADC is main input decice
      c = get_com_char();
      if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
         com[RCVR_PORT].rcv_error = 0;
         //!!!!!qqqq    goto rst_msg;
      }
   }
   else {  // ADC is auxiliary input device (/et=)
      c = get_dac_char();  // aaattt
      if(com[DAC_PORT].rcv_error) {      // parity/framing/overrun errors
         com[DAC_PORT].rcv_error = 0;
         //!!!!!qqqq    goto rst_msg;
      }
   }

   last_c = c;

   if(dac_sync == 0) {    // syncing to start of message, search for a line feed
      if((c == 0x0D) || (c == 0x0A)) {
         dac_sync = 1;
         get_sync_time();
      }
      dac_wptr = 0;
      dac_rptr = 0;
      return;
   }
   else if(dac_sync == 1) { // 0x0A has been seen, now build the message
      if((c == 0x0D) || (c == 0x0A)) {
         if(dac_wptr == 0) return; // end-of-line with no data in the message buffer
         goto dac_end;  // end of message
      }

      if(dac_wptr < MAX_TSIP) {   // add char to the message buffer
         dac_buf[dac_wptr++] = c;
      }
      else {  // buffer overflow, ignore the message
//         dac_error |= 0x8000;  // aaattt
         goto rst_msg;
      }
   }
   else {  // end of message
      dac_end:
      if(dac_wptr) {           // we have a message
         decode_dac_msg(port); // process the message
         packet_end = 1;
      }

      rst_msg:
      dac_wptr = 0;     // prepare for next message
      dac_rptr = 0;
      if((c == 0x0D) || (c == 0x0A)) dac_sync = 1;
      else dac_sync = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %r14d
callq 0xb771
testl %eax, %eax
je 0x9cd36
movl %r14d, %edi
callq 0x1d93f
cmpl $0xa, %r14d
jne 0x9cd48
callq 0x51891
movl %eax, %ebx
leaq 0x25b5bb(%rip), %rax    # 0x2f82e0
cmpb $0x0, 0x17a12(%rax)
je 0x9cd68
addq $0x17a12, %rax          # imm = 0x17A12
jmp 0x9cd65
movl %r14d, %edi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d61b
callq 0x519a0
movl %eax, %ebx
leaq 0x25b58a(%rip), %rax    # 0x2f82e0
cmpb $0x0, 0x24852(%rax)
je 0x9cd68
addq $0x24852, %rax          # imm = 0x24852
movb $0x0, (%rax)
leaq 0x28851d(%rip), %r15    # 0x32528c
movl (%r15), %eax
cmpl $0x1, %eax
je 0x9cdad
testl %eax, %eax
jne 0x9cdc8
cmpb $0xd, %bl
je 0x9cd88
movzbl %bl, %eax
cmpl $0xa, %eax
jne 0x9cd94
movl $0x1, (%r15)
callq 0x51a2f
leaq 0x2884e9(%rip), %rax    # 0x325284
andl $0x0, (%rax)
leaq 0x2884e3(%rip), %rax    # 0x325288
andl $0x0, (%rax)
jmp 0x9ce37
cmpb $0xd, %bl
je 0x9cdba
movzbl %bl, %eax
cmpl $0xa, %eax
jne 0x9ce16
leaq 0x2884c3(%rip), %rax    # 0x325284
cmpl $0x0, (%rax)
jne 0x9cdd4
jmp 0x9ce37
leaq 0x2884b5(%rip), %rax    # 0x325284
cmpl $0x0, (%rax)
je 0x9cde6
movl %r14d, %edi
callq 0x9cc30
movl $0x1, 0x2b8eae(%rip)    # 0x355c94
leaq 0x288497(%rip), %rax    # 0x325284
andl $0x0, (%rax)
leaq 0x288491(%rip), %rax    # 0x325288
andl $0x0, (%rax)
cmpb $0xd, %bl
je 0x9ce07
movzbl %bl, %eax
cmpl $0xa, %eax
jne 0x9ce10
movl $0x1, (%r15)
jmp 0x9ce37
andl $0x0, (%r15)
jmp 0x9ce37
leaq 0x288467(%rip), %rcx    # 0x325284
movslq (%rcx), %rax
cmpq $0xfff, %rax            # imm = 0xFFF
jg 0x9cde6
leal 0x1(%rax), %edx
movl %edx, (%rcx)
leaq 0x28744c(%rip), %rcx    # 0x324280
movb %bl, (%rcx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq