// File: jkingan[P]ladyheather/heather.cpp
// Function: serial_input_check()
int serial_input_check()
{
int i;
static int count = 0;
#define THROTTLE 20

   // returns true if a character is available from the serial port
   // But, we might need to occasionally allow the keyboard to be
   // checked for some polled devices or high nav rate modes.


   if(GetMsecs() > last_kbd_msec) {  // we haven't checked the keyboard in a while
//sprintf(out, "GetMsecs:%.0f  last:%.0f  %.0f    ", GetMsecs(), last_kbd_msec, GetMsecs()-last_kbd_msec);
//DEBUGSTR(out);
//refresh_page();
//    reset_kbd_timer();
      return 0;
   }

   if((nav_rate > 10) && (got_timing_msg % 5) == 4) i = 0;
   else if(rcvr_type == NO_RCVR) i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   else if(rcvr_type == TIDE_RCVR) i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   else if(sim_file) i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   else if(com[RCVR_PORT].process_com == 0) i = 0;
   else if(1 && (rcvr_type == CS_RCVR)) {
      if((++count % THROTTLE) == 0) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && (rcvr_type == LPFRS_RCVR)) {
      if((++count % THROTTLE) < (THROTTLE/2)) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && (rcvr_type == PRS_RCVR)) {
      if((++count % THROTTLE) < (THROTTLE/2)) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && (rcvr_type == SA35_RCVR)) {
      if((++count % THROTTLE) < (THROTTLE/2)) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && (rcvr_type == SRO_RCVR)) {
      if((++count % THROTTLE) < (THROTTLE/2)) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && (rcvr_type == STAR_RCVR) && (star_type == OSA_TYPE)) {
//OSA i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
      if((++count % 50) < (3)) i = 0;
      else i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
   }
   else if(1 && ((++count % THROTTLE) == 0)) {  // mainly for NEC_TYPE GPSDO and ACRON_RCVR
      if(SER_AVAIL_RCVR) {   // polled receivers that need some access to the keyboard
         dup_star_time = 0;
         i = 0;
      }
      else {
         i = SERIAL_DATA_AVAILABLE(RCVR_PORT);
      }
   }
   else i = SERIAL_DATA_AVAILABLE(RCVR_PORT); // check if serial port has data (and stay in loop until it's exhausted)

   return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
callq 0xb630
ucomisd 0x340e33(%rip), %xmm0   # 0x36c778
jbe 0x2b953
movl $0x0, -0x4(%rbp)
jmp 0x2bc1a
movsd 0x24ebdd(%rip), %xmm0   # 0x27a538
movsd 0x14375d(%rip), %xmm1   # 0x16f0c0
ucomisd %xmm1, %xmm0
jbe 0x2b989
movl 0x340cad(%rip), %eax    # 0x36c61c
movl $0x5, %ecx
xorl %edx, %edx
divl %ecx
cmpl $0x4, %edx
jne 0x2b989
movl $0x0, -0x8(%rbp)
jmp 0x2bc14
cmpq $0x400, 0x24c11c(%rip) # imm = 0x400
jne 0x2b9a8
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc12
cmpq $0x800000, 0x24c0fd(%rip) # imm = 0x800000
jne 0x2b9c7
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc10
cmpq $0x0, 0x271bd1(%rip)    # 0x29d5a0
je 0x2b9e3
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc0e
cmpl $0x0, 0x3594ca(%rip)    # 0x384eb4
jne 0x2b9f8
movl $0x0, -0x8(%rbp)
jmp 0x2bc0c
cmpq $0x20000, 0x24c0ad(%rip) # imm = 0x20000
jne 0x2ba3c
movl 0x373df9(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373df0(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2ba2a
movl $0x0, -0x8(%rbp)
jmp 0x2ba37
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc0a
cmpq $0x10000000, 0x24c069(%rip) # imm = 0x10000000
jne 0x2ba80
movl 0x373db5(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373dac(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2ba6e
movl $0x0, -0x8(%rbp)
jmp 0x2ba7b
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc08
cmpq $0x1000000, 0x24c025(%rip) # imm = 0x1000000
jne 0x2bac4
movl 0x373d71(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373d68(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2bab2
movl $0x0, -0x8(%rbp)
jmp 0x2babf
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc06
movabsq $0x1000000000, %rax     # imm = 0x1000000000
cmpq %rax, 0x24bfdb(%rip)    # 0x277ab0
jne 0x2bb0e
movl 0x373d27(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373d1e(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2bafc
movl $0x0, -0x8(%rbp)
jmp 0x2bb09
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc04
cmpq $0x8000000, 0x24bf97(%rip) # imm = 0x8000000
jne 0x2bb52
movl 0x373ce3(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373cda(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0xa, %edx
jge 0x2bb40
movl $0x0, -0x8(%rbp)
jmp 0x2bb4d
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc02
cmpq $0x1000, 0x24bf53(%rip) # imm = 0x1000
jne 0x2bb9c
cmpl $0x4f, 0x24e662(%rip)   # 0x27a1c8
jne 0x2bb9c
movl 0x373c96(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373c8d(%rip)    # 0x39f804
movl $0x32, %ecx
cltd
idivl %ecx
cmpl $0x3, %edx
jge 0x2bb8d
movl $0x0, -0x8(%rbp)
jmp 0x2bb9a
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc00
movl 0x373c62(%rip), %eax    # 0x39f804
addl $0x1, %eax
movl %eax, 0x373c59(%rip)    # 0x39f804
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x2bbf1
movabsq $0x101b465000, %rax     # imm = 0x101B465000
andq 0x24bee7(%rip), %rax    # 0x277ab0
cmpq $0x0, %rax
je 0x2bbe2
movl $0x0, 0x24e5f7(%rip)    # 0x27a1d0
movl $0x0, -0x8(%rbp)
jmp 0x2bbef
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bbfe
movl $0xa, %edi
callq 0xcad0
movl %eax, -0x8(%rbp)
jmp 0x2bc00
jmp 0x2bc02
jmp 0x2bc04
jmp 0x2bc06
jmp 0x2bc08
jmp 0x2bc0a
jmp 0x2bc0c
jmp 0x2bc0e
jmp 0x2bc10
jmp 0x2bc12
jmp 0x2bc14
movl -0x8(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)