// File: /workspace/github_cpp_makefile_star2_O3/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, 0x31bbcf(%rip)    # 0x337024
je 0x1b458
retq
movl 0x3251c2(%rip), %ecx    # 0x340620
movl $0x1, %eax
orl 0x223ae7(%rip), %ecx    # 0x23ef50
jne 0x1b457
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
cmpl $0x0, 0x1ffda0(%rip)    # 0x21b218
jne 0x1b47f
callq 0xd5aa
movl $0x1, %edi
callq 0x90b38
callq 0x1e9b4
callq 0x1e79b
testl %eax, %eax
je 0x1b4c8
movl %eax, %ebx
callq 0xd1efe
movsd 0x2f22c2(%rip), %xmm0   # 0x30d768
movsd %xmm0, 0x30a83a(%rip)   # 0x325ce8
movb $0x0, 0x30a83b(%rip)    # 0x325cf0
movl %ebx, %edi
callq 0x1e61e
callq 0x1e5c3
callq 0x1c461
jmp 0x1b471
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, 0x1fd3f7(%rip)    # 0x2188d0
jne 0x1b4e0
callq 0xc0e87
movb $0x0, 0x31bb41(%rip)    # 0x337028
movl $0xa, %edi
callq 0x1e66a
callq 0x1c461
movq 0x1fd3d3(%rip), %rax    # 0x2188d0
cmpq $0x400, %rax            # imm = 0x400
je 0x1b6de
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1b6de
cmpl $0x0, 0x30a7ac(%rip)    # 0x325cc8
jne 0x1b6de
cmpb $0x1, 0x30a7c7(%rip)    # 0x325cf0
jne 0x1b6de
movb $0x2, 0x30a7ba(%rip)    # 0x325cf0
cmpl $0x0, 0x30a797(%rip)    # 0x325cd4
je 0x1b5b8
leaq 0xef8d5(%rip), %rcx     # 0x10ae1b
xorl %edi, %edi
xorl %esi, %esi
movl $0xc, %edx
callq 0xe787
callq 0xab54
incl 0x31baad(%rip)          # 0x33700c
movl 0x30a78f(%rip), %ecx    # 0x325cf4
testl %ecx, %ecx
setne %dl
movl 0x30a758(%rip), %eax    # 0x325cc8
testl %eax, %eax
sete %sil
testb %sil, %dl
jne 0x1b625
cmpl $0x0, 0x1ffaa2(%rip)    # 0x21b028
jne 0x1b625
movq 0x1fd33d(%rip), %rdx    # 0x2188d0
movabsq $0x101b0e5018, %rsi     # imm = 0x101B0E5018
testq %rsi, %rdx
sete %sil
cmpq $0x100, %rdx            # imm = 0x100
setne %dl
testb %sil, %dl
je 0x1b625
jmp 0x1b6bc
leaq 0xef8a8(%rip), %rcx     # 0x10ae67
xorl %edi, %edi
xorl %esi, %esi
movl $0xc, %edx
callq 0xe787
callq 0xab54
cmpl $0x0, 0x30a71b(%rip)    # 0x325cf4
je 0x1b6de
cmpl $0x0, 0x30a6e2(%rip)    # 0x325cc8
jne 0x1b6de
cmpl $0x0, 0x30a6dd(%rip)    # 0x325cd0
je 0x1b6de
xorl %eax, %eax
cmpl $0x0, 0x30849e(%rip)    # 0x323aa0
movl $0x1, %ecx
jne 0x1b61b
cmpl $0x0, 0x308494(%rip)    # 0x323aa4
jne 0x1b61b
cmpb $0x0, 0x308594(%rip)    # 0x323bad
je 0x1b625
movl $0x3, 0x30a6af(%rip)    # 0x325cd4
movq 0x2f284c(%rip), %rbx    # 0x30de78
movq $0x0, 0x2f2841(%rip) # 0x30de78
movl $0x0, 0x1ff9e7(%rip)    # 0x21b028
xorl %edx, %edx
movw %dx, 0x31cc0c(%rip)     # 0x338256
movw %dx, 0x31cc01(%rip)     # 0x338252
movw %dx, 0x31cbfc(%rip)     # 0x338254
testl %ecx, %ecx
sete %cl
testl %eax, %eax
setne %al
orb %cl, %al
jne 0x1b683
movl $0xa, %edi
callq 0xb49e
cmpl $0x0, 0x2238e1(%rip)    # 0x23ef58
jne 0x1b683
movl $0xf4240, %edi          # imm = 0xF4240
callq 0x9540
movq 0x222d06(%rip), %rdi    # 0x23e390
testq %rdi, %rdi
je 0x1b6a9
movl 0x31b977(%rip), %edx    # 0x33700c
movl 0x1ff98d(%rip), %ecx    # 0x21b028
leaq 0xef79a(%rip), %rsi     # 0x10ae3c
xorl %eax, %eax
callq 0x9560
xorl %edi, %edi
xorl %esi, %esi
callq 0x616de
movslq %ebx, %rax
movq %rax, 0x2f27bc(%rip)    # 0x30de78
callq 0xa80b
mulsd 0xed96f(%rip), %xmm0    # 0x109038
addsd 0xed987(%rip), %xmm0    # 0x109058
movsd %xmm0, 0x2f1ebf(%rip)   # 0x30d598
callq 0xab54
movq 0x1fd1eb(%rip), %rax    # 0x2188d0
cmpq $0x400, %rax            # imm = 0x400
jne 0x1b6f4
callq 0xc0e87
jmp 0x1b70a
cmpq $0x800000, %rax         # imm = 0x800000
je 0x1b70a
cmpl $0x0, 0x30a5d1(%rip)    # 0x325cd4
jne 0x1b70a
callq 0xab54
callq 0x1e5c3
callq 0x1e5c3
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq