// File: jkingan[P]ladyheather/heathgps.cpp
// Function: get_uccm_message()
void get_uccm_message()
{
static u08 c = 0;   // samsung
static int row = 0;
static int last_uccm_c = 0x0D;
static int null_decode = 0;
static int time_msg = 0;

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

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

   last_uccm_c = c;
   c = get_com_char();
   if(time_msg == 1) {
      if(c != '5') time_msg = 0;
      else time_msg = 2;
   }
   if(c == 0x0D) return; // samsung

   if(scpi_status) {    // we are reading the SYST:STAT? results
      get_uccm_status(c);
      return;
   }
   else if(uccm_loop) {  // we are reading the UCCM LOOP results
      get_uccm_loop(c);
      return;
   }

   if(com[RCVR_PORT].rcv_error) {      // parity/framing/overrun errors
      com[RCVR_PORT].rcv_error = 0;
//!!!!!qqqq    goto rst_msg;
   }

if(null_decode) {
   null_decode = 0;
   if(c == 0x0A) ;
   else if(c == 0x0D) ;
   else if(c == ' ') return;
   else if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
      tsip_buf[tsip_wptr++] = c;
      tsip_buf[tsip_wptr] = 0;
      tsip_sync = 1;
      return;
   }
}

   if(tsip_sync == 0) {    // syncing to start of message, search for a '>'
      if(c == '>') {
         tsip_sync = 1;
         get_sync_time();
      }
      else if((c == 'C') || (c == 'c')) {
         tsip_sync = 2; // maybe the time field?
         time_msg = 1;
         get_sync_time();
      }
      else {
         tsip_sync = 1;
         get_sync_time();
      }
if((last_uccm_c == 0x0A) || (last_uccm_c == 0x0D)) {   // samsung
   if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
      tsip_buf[tsip_wptr++] = c;
      tsip_buf[tsip_wptr] = 0;
      tsip_sync = 1;
   }
   return;
}

      rst_msg:
      tsip_wptr = 0;
      tsip_rptr = 0;
      return;
   }
   else if(tsip_sync == 1) { // '>' has been seen, now build the message
      if(c == 0x0A) goto uccm_end; 
      else if(c == 0x0D)  goto uccm_end; 
      else if(c == '>')  {  // null response to UCCM command
         decode_uccm_msg(1);
         packet_end = 1;
         null_decode = 1;  // put next char in tsip_bug
         tsip_sync = 1;
         tsip_rptr = 0;
         tsip_wptr = 0;
         return;
      }


      if(tsip_wptr < (MAX_TSIP-1)) {  // so add it to the message buffer
         tsip_buf[tsip_wptr++] = c;
         tsip_buf[tsip_wptr] = 0;
      }
      else {
         tsip_sync = 0;
         goto rst_msg;
      }
if(time_msg && (last_uccm_c = 'c') && (c == 'a')) {  // samsung does not end time message with 0x0D 0x0A
   if(strlen((char *) tsip_buf) > 130) {
      goto uccm_end;
   }
}
   }
   else if(tsip_sync == 2) {  // C5 timecode message
      if(c == '5') {
         if(tsip_wptr < (MAX_TSIP-2)) {  // so add it to the message buffer
            tsip_buf[tsip_wptr++] = 'C';
            tsip_buf[tsip_wptr++] = '5';
            tsip_buf[tsip_wptr] = 0;
            tsip_sync = 1;
         }
      }
      else tsip_sync = 0;
   }
   else {
      uccm_end:
//if(debug_file) fprintf(debug_file, "Got:: {%s}\n", tsip_buf);
      decode_uccm_msg(2);
      packet_end = 1;
      tsip_sync = 0;
      time_msg = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl $0xa, %edi
callq 0xcad0
cmpl $0x0, %eax
jne 0xdb502
movl $0xa, %edi
callq 0x2b610
jmp 0xdb9ad
movl $0xa, %edi
callq 0x2bd30
movzbl 0x2f5ccd(%rip), %eax    # 0x3d11e0
movl %eax, 0xee10b(%rip)     # 0x1c9624
callq 0x79fc0
movb %al, 0x2f5cbc(%rip)     # 0x3d11e0
cmpl $0x1, 0x2f5cc1(%rip)    # 0x3d11ec
jne 0xdb551
movzbl 0x2f5cac(%rip), %eax    # 0x3d11e0
cmpl $0x35, %eax
je 0xdb545
movl $0x0, 0x2f5ca9(%rip)    # 0x3d11ec
jmp 0xdb54f
movl $0x2, 0x2f5c9d(%rip)    # 0x3d11ec
jmp 0xdb551
movzbl 0x2f5c88(%rip), %eax    # 0x3d11e0
cmpl $0xd, %eax
jne 0xdb562
jmp 0xdb9ad
cmpl $0x0, 0x2f3c4b(%rip)    # 0x3cf1b4
je 0xdb57c
movzbl 0x2f5c6e(%rip), %edi    # 0x3d11e0
callq 0xda8d0
jmp 0xdb9ad
cmpl $0x0, 0x2f3c39(%rip)    # 0x3cf1bc
je 0xdb596
movzbl 0x2f5c54(%rip), %edi    # 0x3d11e0
callq 0xdb200
jmp 0xdb9ad
jmp 0xdb598
leaq 0x291f21(%rip), %rax    # 0x36d4c0
cmpb $0x0, 0x17a12(%rax)
je 0xdb5b6
leaq 0x291f11(%rip), %rax    # 0x36d4c0
movb $0x0, 0x17a12(%rax)
cmpl $0x0, 0x2f5c2b(%rip)    # 0x3d11e8
je 0xdb66e
movl $0x0, 0x2f5c1b(%rip)    # 0x3d11e8
movzbl 0x2f5c0c(%rip), %eax    # 0x3d11e0
cmpl $0xa, %eax
jne 0xdb5de
jmp 0xdb66c
movzbl 0x2f5bfb(%rip), %eax    # 0x3d11e0
cmpl $0xd, %eax
jne 0xdb5ec
jmp 0xdb66a
movzbl 0x2f5bed(%rip), %eax    # 0x3d11e0
cmpl $0x20, %eax
jne 0xdb5fd
jmp 0xdb9ad
leaq 0x2bbe2e(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xdb666
movb 0x2f5bcc(%rip), %dl     # 0x3d11e0
leaq 0x2bbe17(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2bbe06(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2badf5(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2bbded(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2baddf(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
leaq 0x2bbdda(%rip), %rax    # 0x397436
movw $0x1, (%rax)
jmp 0xdb9ad
jmp 0xdb668
jmp 0xdb66a
jmp 0xdb66c
jmp 0xdb66e
leaq 0x2bbdc1(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x0, %eax
jne 0xdb782
movzbl 0x2f5b58(%rip), %eax    # 0x3d11e0
cmpl $0x3e, %eax
jne 0xdb6a0
leaq 0x2bbda2(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
jmp 0xdb6e8
movzbl 0x2f5b39(%rip), %eax    # 0x3d11e0
cmpl $0x43, %eax
je 0xdb6b8
movzbl 0x2f5b2d(%rip), %eax    # 0x3d11e0
cmpl $0x63, %eax
jne 0xdb6d5
leaq 0x2bbd77(%rip), %rax    # 0x397436
movw $0x2, (%rax)
movl $0x1, 0x2f5b1e(%rip)    # 0x3d11ec
callq 0x7a1d0
jmp 0xdb6e6
leaq 0x2bbd5a(%rip), %rax    # 0x397436
movw $0x1, (%rax)
callq 0x7a1d0
jmp 0xdb6e8
cmpl $0xa, 0xedf35(%rip)     # 0x1c9624
je 0xdb6fa
cmpl $0xd, 0xedf2c(%rip)     # 0x1c9624
jne 0xdb763
leaq 0x2bbd31(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xdb75e
movb 0x2f5acf(%rip), %dl     # 0x3d11e0
leaq 0x2bbd1a(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2bbd09(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2bacf8(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2bbcf0(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2bace2(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
leaq 0x2bbcdd(%rip), %rax    # 0x397436
movw $0x1, (%rax)
jmp 0xdb9ad
jmp 0xdb765
leaq 0x2bbcc6(%rip), %rax    # 0x397432
movw $0x0, (%rax)
leaq 0x2bbcbc(%rip), %rax    # 0x397434
movw $0x0, (%rax)
jmp 0xdb9ad
leaq 0x2bbcad(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x1, %eax
jne 0xdb8c0
movzbl 0x2f5a44(%rip), %eax    # 0x3d11e0
cmpl $0xa, %eax
jne 0xdb7a6
jmp 0xdb97f
movzbl 0x2f5a33(%rip), %eax    # 0x3d11e0
cmpl $0xd, %eax
jne 0xdb7b7
jmp 0xdb97f
movzbl 0x2f5a22(%rip), %eax    # 0x3d11e0
cmpl $0x3e, %eax
jne 0xdb80a
movl $0x1, %edi
callq 0xd9f40
movl $0x1, 0x2ef69d(%rip)    # 0x3cae74
movl $0x1, 0x2f5a07(%rip)    # 0x3d11e8
leaq 0x2bbc4e(%rip), %rax    # 0x397436
movw $0x1, (%rax)
leaq 0x2bbc40(%rip), %rax    # 0x397434
movw $0x0, (%rax)
leaq 0x2bbc32(%rip), %rax    # 0x397432
movw $0x0, (%rax)
jmp 0xdb9ad
jmp 0xdb80c
jmp 0xdb80e
leaq 0x2bbc1d(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xfff, %eax            # imm = 0xFFF
jge 0xdb868
movb 0x2f59bb(%rip), %dl     # 0x3d11e0
leaq 0x2bbc06(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %si
addw $0x1, %si
leaq 0x2bbbf5(%rip), %rcx    # 0x397432
movw %si, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2babe4(%rip), %rax    # 0x396430
movb %dl, (%rax,%rcx)
leaq 0x2bbbdc(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2babce(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
jmp 0xdb879
leaq 0x2bbbc7(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xdb765
cmpl $0x0, 0x2f596c(%rip)    # 0x3d11ec
je 0xdb8bb
movl $0x63, 0xedd98(%rip)    # 0x1c9624
movb $0x1, %al
testb $0x1, %al
jne 0xdb894
jmp 0xdb8bb
movzbl 0x2f5945(%rip), %eax    # 0x3d11e0
cmpl $0x61, %eax
jne 0xdb8bb
leaq 0x2bab89(%rip), %rdi    # 0x396430
callq 0x9120
cmpq $0x82, %rax
jbe 0xdb8b9
jmp 0xdb97f
jmp 0xdb8bb
jmp 0xdb9ab
leaq 0x2bbb6f(%rip), %rax    # 0x397436
movzwl (%rax), %eax
cmpl $0x2, %eax
jne 0xdb97d
movzbl 0x2f5906(%rip), %eax    # 0x3d11e0
cmpl $0x35, %eax
jne 0xdb96f
leaq 0x2bbb48(%rip), %rax    # 0x397432
movzwl (%rax), %eax
cmpl $0xffe, %eax            # imm = 0xFFE
jge 0xdb96d
leaq 0x2bbb37(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %dx
addw $0x1, %dx
leaq 0x2bbb26(%rip), %rcx    # 0x397432
movw %dx, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2bab15(%rip), %rax    # 0x396430
movb $0x43, (%rax,%rcx)
leaq 0x2bbb0c(%rip), %rax    # 0x397432
movw (%rax), %ax
movw %ax, %dx
addw $0x1, %dx
leaq 0x2bbafb(%rip), %rcx    # 0x397432
movw %dx, (%rcx)
movzwl %ax, %eax
movl %eax, %ecx
leaq 0x2baaea(%rip), %rax    # 0x396430
movb $0x35, (%rax,%rcx)
leaq 0x2bbae1(%rip), %rax    # 0x397432
movzwl (%rax), %eax
movl %eax, %ecx
leaq 0x2baad3(%rip), %rax    # 0x396430
movb $0x0, (%rax,%rcx)
leaq 0x2bbace(%rip), %rax    # 0x397436
movw $0x1, (%rax)
jmp 0xdb97b
leaq 0x2bbac0(%rip), %rax    # 0x397436
movw $0x0, (%rax)
jmp 0xdb9a9
jmp 0xdb97f
movl $0x2, %edi
callq 0xd9f40
movl $0x1, 0x2ef4e1(%rip)    # 0x3cae74
leaq 0x2bba9c(%rip), %rax    # 0x397436
movw $0x0, (%rax)
movl $0x0, 0x2f5843(%rip)    # 0x3d11ec
jmp 0xdb9ab
jmp 0xdb9ad
popq %rbp
retq
nop