// File: /workspace/github_cpp_makefile_star2_O2/jkingan[P]ladyheather/heather.cpp
// Function: serve_gps(int)
S32 serve_gps(int why)  // called from either foreground loop or WM_TIMER (e.g., while dragging)
{
S32 i;
int served;
int old_survey;

   if(break_flag) return 0;        // ctrl-break pressed, so exit the program
   if(take_a_dump) return 1;
   if(in_terminal) return 1;

   while(1) {

      served = 0;
      #ifdef WIN_VFX
         if(!timer_serve) {
            served = 1;
            serve_vfx();
         }
      #endif
      #ifdef USE_X11
         if(!timer_serve) {
            get_x11_event();
            served = 1;
         }
      #endif
      #ifdef USE_SDL
         if(!timer_serve) {
    	     get_sdl_event();
	         served = 1;
	     }
      #endif
fake_second_check(1);
fine_tick_check();


      i = serial_input_check();  // see if OK to process the receiver serial port data

      if(i == 0) {    // no data available,  we are not too busy
if(rcvr_type == Z12_RCVR) {
   get_rcvr_message();
}
         // no data available,  we are not too busy, or taking a breather from high nav-rate updates
         system_busy = 0;
         check_com_timer(RCVR_PORT);
         get_mouse_info();

         if(rcvr_type == NO_RCVR) ;
         else if(rcvr_type == TIDE_RCVR) ;
         else if(com[RCVR_PORT].user_disabled_com) ;
         else if(com[RCVR_PORT].com_data_lost == DATA_LOSS_REINIT) { // attempt to restart the receiver
            com[RCVR_PORT].com_data_lost = DATA_LOSS_NO_INIT;  // prevents futile re-init attempts
            if(com[RCVR_PORT].process_com) {
               vidstr(0,0, RED, "NO DATA SEEN ON COM DEVICE      ");
               refresh_page();
               ++restart_count;
               if((com[RCVR_PORT].com_recover && !com[RCVR_PORT].user_disabled_com) || rcvr_reset || POLLED_RCVR || (rcvr_type == ZODIAC_RCVR)) {    // recover from hard reset
                  com_retry:
                  old_survey = do_survey;
                  do_survey = 0;
                  rcvr_reset = 0;
                  tsip_sync = 0;
                  tsip_wptr = 0;
                  tsip_rptr = 0;
                  if(com[RCVR_PORT].com_recover && !com[RCVR_PORT].user_disabled_com) {
                     init_com(RCVR_PORT, 5);
                     if(first_key == 0) Sleep(1000);
                  }

                  if(debug_file) {
                     fprintf(debug_file, "!!! RCVR_PORT DATA LOSS RESET #%d: %d !!!\n", restart_count, rcvr_reset);
                  }
                  init_messages(0, 0);
                  do_survey = old_survey;
               }
reset_kbd_timer();
               refresh_page();
            }
            else {
               vidstr(0,0, RED, "COM DATA DEVICE UNAVAILABLE     ");
               refresh_page();
               if((com[RCVR_PORT].com_recover && !com[RCVR_PORT].user_disabled_com) && com[RCVR_PORT].com_running) {
                  if(com[RCVR_PORT].com_port || com[RCVR_PORT].usb_port || com[RCVR_PORT].IP_addr[0]) com[RCVR_PORT].process_com = 3;
                  goto com_retry;
               }
            }
         }

         if(rcvr_type == NO_RCVR) get_rcvr_message();
         else if(rcvr_type == TIDE_RCVR) ;
         else if(com[RCVR_PORT].process_com == 0) refresh_page();

process_extra_ports(3);
         break;
      }
      else {
         reset_com_timer(RCVR_PORT);
      }

      get_device_messages(i);  // process any data from the input devices
      process_extra_ports(4);   // process the extra devices

      if(get_mouse_info() == 0) {     // show queue data at the mouse cursor
         if(i == 0) refresh_page();   // keep refreshing page in case no serial data
      }
   }
process_extra_ports(5);

   return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
cmpl $0x0, 0x3067b9(%rip)    # 0x321024
jne 0x1aaf5
movl 0x30fda9(%rip), %eax    # 0x32a620
orl 0x20e6d3(%rip), %eax    # 0x228f50
jne 0x1a8c8
pushq $0x1
popq %rbx
pushq $0xa
popq %r14
cmpl $0x0, 0x1ea98b(%rip)    # 0x205218
jne 0x1a894
callq 0xd209
movl %ebx, %edi
callq 0x83d34
callq 0x1d8f0
callq 0x1d737
testl %eax, %eax
je 0x1a8d0
movl %eax, %r15d
movl %r14d, %edi
callq 0x1d93f
movl %r15d, %edi
callq 0x1d5cf
callq 0x1d57a
callq 0x1b5eb
jmp 0x1a886
pushq $0x1
popq %rbx
jmp 0x1aaf5
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, 0x1e7fef(%rip)    # 0x2028d0
jne 0x1a8e8
callq 0xaffcb
movb $0x0, 0x306739(%rip)    # 0x321028
pushq $0xa
popq %rdi
callq 0x1d61b
callq 0x1b5eb
movq 0x1e7fcd(%rip), %rax    # 0x2028d0
cmpq $0x400, %rax            # imm = 0x400
je 0x1aabf
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1aabf
cmpl $0x0, 0x2f53a6(%rip)    # 0x30fcc8
jne 0x1aabf
cmpb $0x1, 0x2f53c1(%rip)    # 0x30fcf0
jne 0x1aabf
movb $0x2, 0x2f53b4(%rip)    # 0x30fcf0
cmpl $0x0, 0x2f5391(%rip)    # 0x30fcd4
je 0x1a9bc
leaq 0xda54a(%rip), %rcx     # 0xf4e96
pushq $0xc
popq %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0xe2d2
callq 0xaa05
incl 0x3066a9(%rip)          # 0x32100c
movl 0x2f538b(%rip), %ecx    # 0x30fcf4
testl %ecx, %ecx
setne %dl
movl 0x2f5354(%rip), %eax    # 0x30fcc8
testl %eax, %eax
sete %sil
testb %sil, %dl
jne 0x1aa25
cmpl $0x0, 0x1ea69e(%rip)    # 0x205028
jne 0x1aa25
movq 0x1e7f39(%rip), %rdx    # 0x2028d0
movabsq $0x101b0e5018, %rsi     # imm = 0x101B0E5018
testq %rsi, %rdx
sete %sil
cmpq $0x100, %rdx            # imm = 0x100
setne %dl
testb %sil, %dl
je 0x1aa25
jmp 0x1aab5
leaq 0xda51f(%rip), %rcx     # 0xf4ee2
pushq $0xc
popq %rdx
xorl %edi, %edi
xorl %esi, %esi
callq 0xe2d2
callq 0xaa05
cmpl $0x0, 0x2f5319(%rip)    # 0x30fcf4
je 0x1aabf
cmpl $0x0, 0x2f52e0(%rip)    # 0x30fcc8
jne 0x1aabf
cmpl $0x0, 0x2f52db(%rip)    # 0x30fcd0
je 0x1aabf
xorl %eax, %eax
cmpl $0x0, 0x2f309c(%rip)    # 0x30daa0
pushq $0x1
popq %rcx
jne 0x1aa1b
cmpl $0x0, 0x2f3094(%rip)    # 0x30daa4
jne 0x1aa1b
cmpb $0x0, 0x2f3194(%rip)    # 0x30dbad
je 0x1aa25
movl $0x3, 0x2f52af(%rip)    # 0x30fcd4
movq 0x2dd44c(%rip), %r14    # 0x2f7e78
andq $0x0, 0x2dd444(%rip)    # 0x2f7e78
andl $0x0, 0x1ea5ed(%rip)    # 0x205028
andw $0x0, 0x307813(%rip)    # 0x322256
andw $0x0, 0x307807(%rip)    # 0x322252
andw $0x0, 0x307801(%rip)    # 0x322254
testl %ecx, %ecx
sete %cl
testl %eax, %eax
setne %al
orb %cl, %al
jne 0x1aa7c
pushq $0xa
popq %rdi
callq 0xb30a
cmpl $0x0, 0x20e4e8(%rip)    # 0x228f58
jne 0x1aa7c
movl $0x3e8, %edi            # imm = 0x3E8
callq 0xae83
movq 0x20d90d(%rip), %rdi    # 0x228390
testq %rdi, %rdi
je 0x1aaa2
movl 0x30657e(%rip), %edx    # 0x32100c
movl 0x1ea594(%rip), %ecx    # 0x205028
leaq 0xda41c(%rip), %rsi     # 0xf4eb7
xorl %eax, %eax
callq 0x9560
xorl %edi, %edi
xorl %esi, %esi
callq 0x59afe
movslq %r14d, %rax
movq %rax, 0x2dd3c3(%rip)    # 0x2f7e78
callq 0xad24
callq 0xaa05
movq 0x1e7e0a(%rip), %rax    # 0x2028d0
cmpq $0x400, %rax            # imm = 0x400
jne 0x1aad5
callq 0xaffcb
jmp 0x1aaeb
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1aaeb
cmpl $0x0, 0x2f51f0(%rip)    # 0x30fcd4
jne 0x1aaeb
callq 0xaa05
callq 0x1d57a
callq 0x1d57a
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq