// File: /workspace/github_cpp_makefile_star2_O1/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:
xorl %eax, %eax
cmpl $0x0, 0x31bbee(%rip)    # 0x337024
je 0x1b439
retq
movl 0x3251e1(%rip), %ecx    # 0x340620
movl $0x1, %eax
orl 0x223b06(%rip), %ecx    # 0x23ef50
jne 0x1b438
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
cmpl $0x0, 0x1ffdbf(%rip)    # 0x21b218
jne 0x1b460
callq 0xd5c9
movl $0x1, %edi
callq 0x90ac8
callq 0x1e9d5
callq 0x1e7be
testl %eax, %eax
je 0x1b4a9
movl %eax, %ebx
callq 0xd1865
movsd 0x2f22e1(%rip), %xmm0   # 0x30d768
movsd %xmm0, 0x30a859(%rip)   # 0x325ce8
movb $0x0, 0x30a85a(%rip)    # 0x325cf0
movl %ebx, %edi
callq 0x1e654
callq 0x1e5f9
callq 0x1c406
jmp 0x1b452
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, 0x1fd416(%rip)    # 0x2188d0
jne 0x1b4c1
callq 0xc08a9
movb $0x0, 0x31bb60(%rip)    # 0x337028
movl $0xa, %edi
callq 0x1e6a0
callq 0x1c406
movq 0x1fd3f2(%rip), %rax    # 0x2188d0
cmpq $0x400, %rax            # imm = 0x400
je 0x1b6b5
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1b6b5
cmpl $0x0, 0x30a7cb(%rip)    # 0x325cc8
jne 0x1b6b5
cmpb $0x1, 0x30a7e6(%rip)    # 0x325cf0
jne 0x1b6b5
movb $0x2, 0x30a7d9(%rip)    # 0x325cf0
cmpl $0x0, 0x30a7b6(%rip)    # 0x325cd4
je 0x1b592
leaq 0xef8e4(%rip), %rcx     # 0x10ae0b
xorl %edi, %edi
xorl %esi, %esi
movl $0xc, %edx
callq 0xe7d0
callq 0xab5f
incl 0x31bacc(%rip)          # 0x33700c
cmpl $0x0, 0x30a7ad(%rip)    # 0x325cf4
setne %al
cmpl $0x0, 0x30a777(%rip)    # 0x325cc8
sete %cl
testb %cl, %al
jne 0x1b5f8
cmpl $0x0, 0x1ffac5(%rip)    # 0x21b028
jne 0x1b5f8
movq 0x1fd360(%rip), %rax    # 0x2188d0
movabsq $0x101b0e5018, %rcx     # imm = 0x101B0E5018
testq %rcx, %rax
sete %cl
cmpq $0x100, %rax            # imm = 0x100
setne %al
testb %cl, %al
je 0x1b5f8
jmp 0x1b693
leaq 0xef8be(%rip), %rcx     # 0x10ae57
xorl %edi, %edi
xorl %esi, %esi
movl $0xc, %edx
callq 0xe7d0
callq 0xab5f
cmpl $0x0, 0x30a741(%rip)    # 0x325cf4
je 0x1b6b5
cmpl $0x0, 0x30a708(%rip)    # 0x325cc8
jne 0x1b6b5
cmpl $0x0, 0x30a703(%rip)    # 0x325cd0
je 0x1b6b5
cmpl $0x0, 0x3084c6(%rip)    # 0x323aa0
jne 0x1b5ee
cmpl $0x0, 0x3084c1(%rip)    # 0x323aa4
jne 0x1b5ee
cmpb $0x0, 0x3085c1(%rip)    # 0x323bad
je 0x1b5f8
movl $0x3, 0x30a6dc(%rip)    # 0x325cd4
movq 0x2f2879(%rip), %rbx    # 0x30de78
movq $0x0, 0x2f286e(%rip) # 0x30de78
movl $0x0, 0x1ffa14(%rip)    # 0x21b028
xorl %eax, %eax
movw %ax, 0x31cc39(%rip)     # 0x338256
movw %ax, 0x31cc2e(%rip)     # 0x338252
movw %ax, 0x31cc29(%rip)     # 0x338254
cmpl $0x0, 0x30a6c2(%rip)    # 0x325cf4
je 0x1b65a
cmpl $0x0, 0x30a68d(%rip)    # 0x325cc8
jne 0x1b65a
movl $0xa, %edi
callq 0xb49f
cmpl $0x0, 0x22390a(%rip)    # 0x23ef58
jne 0x1b65a
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x9540
movq 0x222d2f(%rip), %rdi    # 0x23e390
testq %rdi, %rdi
je 0x1b680
movl 0x31b9a0(%rip), %edx    # 0x33700c
movl 0x1ff9b6(%rip), %ecx    # 0x21b028
leaq 0xef7b3(%rip), %rsi     # 0x10ae2c
xorl %eax, %eax
callq 0x9560
xorl %edi, %edi
xorl %esi, %esi
callq 0x61765
movslq %ebx, %rax
movq %rax, 0x2f27e5(%rip)    # 0x30de78
callq 0xa826
mulsd 0xed998(%rip), %xmm0    # 0x109038
addsd 0xed9b0(%rip), %xmm0    # 0x109058
movsd %xmm0, 0x2f1ee8(%rip)   # 0x30d598
callq 0xab5f
movq 0x1fd214(%rip), %rax    # 0x2188d0
cmpq $0x400, %rax            # imm = 0x400
jne 0x1b6cb
callq 0xc08a9
jmp 0x1b6e1
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1b6e1
cmpl $0x0, 0x30a5fa(%rip)    # 0x325cd4
jne 0x1b6e1
callq 0xab5f
callq 0x1e5f9
callq 0x1e5f9
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq