// File: jkingan[P]ladyheather/heather.cpp
// Function: main
int main(int argc, char *argv[])
{
   #ifdef USE_X11
      if(argv[0]) strcpy(exe_name, argv[0]);
      printf("argv[0] (%s)\n", argv[0]);
   #endif

   config_program(argc, argv);  // process command line arguments

   if(1) ;
   else if(((rcvr_type == NO_RCVR) || (rcvr_type == TIDE_RCVR)) && (com[RCVR_PORT].process_com == 0)) {
      com[RCVR_PORT].process_com = 1;
      com[RCVR_PORT].user_disabled_com = 0;
   }

   #ifdef WIN_VFX
     get_screen_size(0);
     if(display_width == 1280) {
        vfx_full:
        if(vfx_fullscreen) {
           SAL_set_preference(SAL_MAXIMIZE_TO_FULLSCREEN, YES);
           initial_window_mode = VFX_TRY_FULLSCREEN;
        }
     }
     else if(display_width == 1024) goto vfx_full;
     else if(display_width == 800)  goto vfx_full;
     else if(display_width == 640)  goto vfx_full;
   #endif

   if(jpl_clock) {
      if(dst_ofs)            time_color = DST_TIME_COLOR;
      else if(time_zone_set) time_color = DST_TIME_COLOR;  // !!! std_time_color is rather dim for the big clock
      else                   time_color = WHITE;
   }

   if(luxor) {
      config_luxor_plots();
   }

   find_endian();     // determine machine byte ordering
   alloc_memory();    // allocate memory for plot and adev queues, etc
   adjust_view();     // tweak screen for user selected view interval, etc


   init_hardware();   // initialize the com port, screen, and any other hardware
   hw_setup = 1;
   update_pwm();

   if(temp_script) {  // heather.cfg created a temporary keyboard script file, process it
      fclose(temp_script);
      temp_script = 0;
      open_script(TEMP_SCRIPT);
   }

   if(take_a_dump) {
      dump_stream(1);
   }

   #ifdef PLM
      init_pl_timer();// setup to monitor power line freq
   #endif
   config_tz_info();  // try to get time zone info from the system
   config_options();  // configure system for command line options

   // user set a log param on the command line, start writing the log file
   if(user_set_log) {
      log_file_time = log_interval + 1;
      open_log_file(log_mode);
      rinex_header_written = 0;
   }

   if(need_debug_log) {
      need_debug_log = 0;
      if(debug_file) fclose(debug_file);
      debug_file = 0;
      debug_name[0] = 0;

      sprintf(out, "debug.log");
      open_debug_file(out);
   }

   if(need_rinex_file) {
      need_rinex_file = 0;
      if(rinex_file) fclose(rinex_file);
      rinex_file = 0;
      rinex_name[0] = 0;

      set_rinex_name();  // into string "out"
      if(out[0]) open_rinex_file(out);
   }

   if(need_raw_file) {  // open raw receiver log file specified on the command line
      need_raw_file = 0;
      if(raw_file) fclose(raw_file);
      raw_file = 0;
      sprintf(raw_name, "%s.raw", "heather");
      raw_file = open_raw_file(raw_name, "wb");
      if(raw_file) log_stream |= LOG_RAW_STREAM;
   }

   if(need_prn_file) {  // open raw receiver log file specified on the command line
      need_prn_file = 0;
      if(prn_file) fclose(prn_file);
      prn_file = 0;
      sprintf(prn_name, "%s.prn", "heather");
      prn_file = open_prn_file(prn_name, "wb");
   }

   if(need_ticc_file) {  // open ticc log file specified on the command line
      need_ticc_file = 0;
      if(ticc_file) fclose(ticc_file);
      ticc_file = 0;
      sprintf(ticc_name, "%s.raw", "ticc");
      ticc_file = topen(ticc_name, "wb");
// aaattt      if(raw_file) log_stream |= LOG_RAW_STREAM;
   }

   if(detect_rcvr_type) {
      auto_detect(0);
      if(rcvr_type == TICC_RCVR) {  // xyzzy  disable watch/azel/signals
         reset_com_timer(RCVR_PORT);
         init_screen(5395);
         reset_com_timer(RCVR_PORT);
not_safe = 3;
      }
   }

   if(ticc_type == PICPET_TICC) {  // scale PICPET wrap interval to 10 MHz clock equivalent
      if(rcvr_type == TICC_RCVR) {
         pet_clock = (double) com[RCVR_PORT].baud_rate / 19200.0;
         if(timestamp_wrap == 0.0) timestamp_wrap = 100.0 / pet_clock;
      }
      else if(ticc_port_open()) {
         pet_clock = (double) com[TICC_PORT].baud_rate / 19200.0;
         if(timestamp_wrap == 0.0) timestamp_wrap = 100.0 / pet_clock;
      }
   }

   if(NO_SATS || (rcvr_type == TIDE_RCVR)) {  // try to get default user position from file
      read_default_lla();
   }

   if(enviro_mode()) {
      config_enviro_plots(1);
   }

   if(user_set_title_bar) { // set title bar text
      set_title_bar(0);
   }
   else if(unit_file_name == 0) {
   }
   else if(unit_file_name[0]) {
      strcpy(szAppName, unit_file_name);
      strupr(szAppName);
szAppName[0] = 0;
      user_set_title_bar = 2;
      set_title_bar(2);
   }

   if(TICC_USED) no_adev_flag = 0;
   else if(0 && no_adev_flag) {
      free_mtie();
      free_adev_queues();

      adev_q_size = 0;
      // disable adevs... if you re-enable them you will need to use
      // the /j command to reset the adev period to a non-zero value!!!!!
      adev_q_size = 1L;
      adev_period = 0.0;
      pps_adev_period = adev_period;
      osc_adev_period = adev_period;
      chc_adev_period = adev_period;
      chd_adev_period = adev_period;
      save_adev_period();
   }

   plot_axes();         // draw graph axes
   if(luxor) reset_luxor_wdt(1);
   show_version_header();
   show_log_state();    // show logging state
   show_com_state();    // show com port state and flush buffer
   get_log_file();      // read in any initial log file
   read_rpn_file(rpn_name, 1);  // read in any calculator user defined functions

   if(monitor_mode) {
      set_monitor_mode(0); // port monitor
   }
   else if(enable_terminal) {
      do_term(term_port);  // debug terminal
      if(rcvr_type == NO_RCVR) goto exit_pgm;
      if(rcvr_type == TERM_RCVR) goto exit_pgm;
   }

   reset_com_timer(RCVR_PORT);

   if(need_view_auto) {     // force a VT auto view command
      add_kbd('v');
      add_kbd('t');
      add_kbd(0x0D);
   }

   if(calc_rcvr) {
      start_calc_zoom(1);
   }

   do_gps();            // run the receiver until something says stop

   exit_pgm:
   clean_up();          // leave the receiver in a nice stand-alone state
   shut_down(0);        // clean up remaining details and exit
   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x2da53
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x371572(%rip), %rdi    # 0x39efc0
callq 0x9350
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x143af3(%rip), %rdi    # 0x171554
movb $0x0, %al
callq 0x9030
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
callq 0x2d5a0
cmpl $0x0, 0x249f51(%rip)    # 0x2779cc
je 0x2dab5
cmpl $0x0, 0x33effc(%rip)    # 0x36ca80
je 0x2da92
movl $0xb, 0x254d24(%rip)    # 0x2827b4
jmp 0x2dab3
cmpb $0x0, 0x33efdb(%rip)    # 0x36ca74
je 0x2daa7
movl $0xb, 0x254d0f(%rip)    # 0x2827b4
jmp 0x2dab1
movl $0xf, 0x254d03(%rip)    # 0x2827b4
jmp 0x2dab3
jmp 0x2dab5
cmpb $0x0, 0x270662(%rip)    # 0x29e11e
je 0x2dac3
callq 0x68600
callq 0x130c0
callq 0x14480
callq 0x29030
callq 0xd3f0
movl $0x1, 0x24c733(%rip)    # 0x27a214
callq 0x11ee60
cmpq $0x0, 0x26faa2(%rip)    # 0x29d590
je 0x2db13
movq 0x26fa99(%rip), %rdi    # 0x29d590
callq 0x9380
movq $0x0, 0x26fa89(%rip) # 0x29d590
leaq 0x143226(%rip), %rdi    # 0x170d34
callq 0x29570
cmpl $0x0, 0x270616(%rip)    # 0x29e130
je 0x2db26
movl $0x1, %edi
callq 0x2ce40
callq 0x2d7f0
callq 0xfcd0
cmpb $0x0, 0x26faa5(%rip)    # 0x29d5dc
je 0x2db61
movq 0x24ca48(%rip), %rax    # 0x27a588
addq $0x1, %rax
movq %rax, 0x26fa95(%rip)    # 0x29d5e0
movq 0x26f9e6(%rip), %rdi    # 0x29d538
callq 0x10ce00
movl $0x0, 0x26fa6b(%rip)    # 0x29d5cc
cmpb $0x0, 0x26fa60(%rip)    # 0x29d5c8
je 0x2dbba
movb $0x0, 0x26fa57(%rip)    # 0x29d5c8
cmpq $0x0, 0x26f9f7(%rip)    # 0x29d570
je 0x2db87
movq 0x26f9ee(%rip), %rdi    # 0x29d570
callq 0x9380
movq $0x0, 0x26f9de(%rip) # 0x29d570
movb $0x0, 0x26f0a7(%rip)    # 0x29cc40
leaq 0x36d860(%rip), %rdi    # 0x39b400
leaq 0x1431d7(%rip), %rsi    # 0x170d7e
movb $0x0, %al
callq 0x9060
leaq 0x36d84b(%rip), %rdi    # 0x39b400
callq 0xa620
cmpb $0x0, 0x26fa08(%rip)    # 0x29d5c9
je 0x2dc0e
movb $0x0, 0x26f9ff(%rip)    # 0x29d5c9
cmpq $0x0, 0x26f976(%rip)    # 0x29d548
je 0x2dbe0
movq 0x26f96d(%rip), %rdi    # 0x29d548
callq 0x9380
movq $0x0, 0x26f95d(%rip) # 0x29d548
movb $0x0, 0x26e54e(%rip)    # 0x29c140
callq 0xa6e0
cmpb $0x0, 0x36d802(%rip)    # 0x39b400
je 0x2dc0c
leaq 0x36d7f9(%rip), %rdi    # 0x39b400
callq 0xa850
jmp 0x2dc0e
cmpb $0x0, 0x26f9af(%rip)    # 0x29d5c4
je 0x2dc90
movb $0x0, 0x26f9a6(%rip)    # 0x29d5c4
cmpq $0x0, 0x26f92a(%rip)    # 0x29d550
je 0x2dc34
movq 0x26f921(%rip), %rdi    # 0x29d550
callq 0x9380
movq $0x0, 0x26f911(%rip) # 0x29d550
leaq 0x26e5fa(%rip), %rdi    # 0x29c240
leaq 0x143915(%rip), %rsi    # 0x171562
leaq 0x141bf3(%rip), %rdx    # 0x16f847
movb $0x0, %al
callq 0x9060
leaq 0x26e5de(%rip), %rdi    # 0x29c240
leaq 0x1422ae(%rip), %rsi    # 0x16ff17
callq 0xa960
movq %rax, 0x26f8db(%rip)    # 0x29d550
cmpq $0x0, 0x26f8d3(%rip)    # 0x29d550
je 0x2dc8e
movl 0x26f96b(%rip), %eax    # 0x29d5f0
orl $0x8, %eax
movl %eax, 0x26f962(%rip)    # 0x29d5f0
jmp 0x2dc90
cmpb $0x0, 0x26f92e(%rip)    # 0x29d5c5
je 0x2dcf7
movb $0x0, 0x26f925(%rip)    # 0x29d5c5
cmpq $0x0, 0x26f8b0(%rip)    # 0x29d558
je 0x2dcb6
movq 0x26f8a7(%rip), %rdi    # 0x29d558
callq 0x9380
movq $0x0, 0x26f897(%rip) # 0x29d558
leaq 0x26e678(%rip), %rdi    # 0x29c340
leaq 0x14389a(%rip), %rsi    # 0x171569
leaq 0x141b71(%rip), %rdx    # 0x16f847
movb $0x0, %al
callq 0x9060
leaq 0x26e65c(%rip), %rdi    # 0x29c340
leaq 0x14222c(%rip), %rsi    # 0x16ff17
callq 0xaa70
movq %rax, 0x26f861(%rip)    # 0x29d558
cmpb $0x0, 0x26f8c9(%rip)    # 0x29d5c7
je 0x2dd5e
movb $0x0, 0x26f8c0(%rip)    # 0x29d5c7
cmpq $0x0, 0x26f859(%rip)    # 0x29d568
je 0x2dd1d
movq 0x26f850(%rip), %rdi    # 0x29d568
callq 0x9380
movq $0x0, 0x26f840(%rip) # 0x29d568
leaq 0x26e711(%rip), %rdi    # 0x29c440
leaq 0x14382c(%rip), %rsi    # 0x171562
leaq 0x143833(%rip), %rdx    # 0x171570
movb $0x0, %al
callq 0x9060
leaq 0x26e6f5(%rip), %rdi    # 0x29c440
leaq 0x1421c5(%rip), %rsi    # 0x16ff17
callq 0x9b20
movq %rax, 0x26f80a(%rip)    # 0x29d568
cmpl $0x0, 0x24c443(%rip)    # 0x27a1a8
je 0x2dda2
xorl %edi, %edi
callq 0x86960
cmpq $0x10000, 0x249d37(%rip) # imm = 0x10000
jne 0x2dda0
movl $0xa, %edi
callq 0x2bd30
movl $0x1513, %edi           # imm = 0x1513
callq 0xd430
movl $0xa, %edi
callq 0x2bd30
movb $0x3, 0x33f2ad(%rip)    # 0x36d04d
jmp 0x2dda2
cmpl $0x50, 0x249d3f(%rip)   # 0x277ae8
jne 0x2de5c
cmpq $0x10000, 0x249cf6(%rip) # imm = 0x10000
jne 0x2de05
cvtsi2sdl 0x3550cc(%rip), %xmm0 # 0x382e90
movsd 0x1414b4(%rip), %xmm1   # 0x16f280
divsd %xmm1, %xmm0
movsd %xmm0, 0x33ddf8(%rip)   # 0x36bbd0
movsd 0x33ddf8(%rip), %xmm0   # 0x36bbd8
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2de03
jp 0x2de03
movsd 0x14125d(%rip), %xmm0   # 0x16f050
divsd 0x33ddd5(%rip), %xmm0   # 0x36bbd0
movsd %xmm0, 0x33ddd5(%rip)   # 0x36bbd8
jmp 0x2de5a
callq 0x992e0
cmpl $0x0, %eax
je 0x2de58
cvtsi2sdl 0x35b799(%rip), %xmm0 # 0x3895b0
movsd 0x141461(%rip), %xmm1   # 0x16f280
divsd %xmm1, %xmm0
movsd %xmm0, 0x33dda5(%rip)   # 0x36bbd0
movsd 0x33dda5(%rip), %xmm0   # 0x36bbd8
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2de56
jp 0x2de56
movsd 0x14120a(%rip), %xmm0   # 0x16f050
divsd 0x33dd82(%rip), %xmm0   # 0x36bbd0
movsd %xmm0, 0x33dd82(%rip)   # 0x36bbd8
jmp 0x2de58
jmp 0x2de5a
jmp 0x2de5c
movabsq $0x105b8b0400, %rax     # imm = 0x105B8B0400
andq 0x249c43(%rip), %rax    # 0x277ab0
cmpq $0x0, %rax
jne 0x2dea8
cmpl $0x0, 0x24c336(%rip)    # 0x27a1b0
je 0x2de85
cmpl $0x0, 0x33e721(%rip)    # 0x36c5a4
je 0x2dea8
cmpq $0x400000, 0x249c20(%rip) # imm = 0x400000
jne 0x2de9b
cmpl $0x0, 0x33ecfb(%rip)    # 0x36cb94
je 0x2dea8
cmpq $0x800000, 0x249c0a(%rip) # imm = 0x800000
jne 0x2dead
callq 0x2d870
callq 0x83ad0
cmpl $0x0, %eax
je 0x2dec1
movl $0x1, %edi
callq 0x50840
cmpl $0x0, 0x36fa50(%rip)    # 0x39d918
je 0x2ded3
xorl %edi, %edi
callq 0x102c0
jmp 0x2df29
cmpq $0x0, 0x1a1f8d(%rip)    # 0x1cfe68
jne 0x2dedf
jmp 0x2df27
movq 0x1a1f82(%rip), %rax    # 0x1cfe68
cmpb $0x0, (%rax)
je 0x2df25
movq 0x1a1f76(%rip), %rsi    # 0x1cfe68
leaq 0x18ed07(%rip), %rdi    # 0x1bcc00
callq 0x9350
leaq 0x18ecfb(%rip), %rdi    # 0x1bcc00
callq 0x9890
movb $0x0, 0x18ecef(%rip)    # 0x1bcc00
movl $0x2, 0x36f9fd(%rip)    # 0x39d918
movl $0x2, %edi
callq 0x102c0
jmp 0x2df27
jmp 0x2df29
cmpq $0x10000, 0x249b7c(%rip) # imm = 0x10000
je 0x2df40
callq 0x992e0
cmpl $0x0, %eax
je 0x2df4c
movl $0x0, 0x26dfca(%rip)    # 0x29bf14
jmp 0x2df4e
jmp 0x2df4e
callq 0x21d00
cmpb $0x0, 0x2701c4(%rip)    # 0x29e11e
je 0x2df66
movl $0x1, %edi
callq 0xacfe0
callq 0x9c6d0
callq 0x10ae40
callq 0x2bda0
callq 0x2c040
leaq 0x26e8bf(%rip), %rdi    # 0x29c840
movl $0x1, %esi
callq 0x310f0
cmpl $0x0, 0x26f686(%rip)    # 0x29d618
je 0x2df9d
xorl %edi, %edi
callq 0x2c7d0
jmp 0x2dfd3
cmpl $0x0, 0x27016c(%rip)    # 0x29e110
je 0x2dfd1
movl 0x33f508(%rip), %edi    # 0x36d4b4
callq 0x2c830
cmpq $0x400, 0x249af4(%rip) # imm = 0x400
jne 0x2dfc0
jmp 0x2e01c
cmpq $0x4000000, 0x249ae5(%rip) # imm = 0x4000000
jne 0x2dfcf
jmp 0x2e01c
jmp 0x2dfd1
jmp 0x2dfd3
movl $0xa, %edi
callq 0x2bd30
cmpl $0x0, 0x24c5bc(%rip)    # 0x27a5a0
je 0x2e004
movl $0x76, %edi
callq 0xf320
movl $0x74, %edi
callq 0xf320
movl $0xd, %edi
callq 0xf320
cmpl $0x0, 0x249ab5(%rip)    # 0x277ac0
je 0x2e017
movl $0x1, %edi
callq 0x2e280
callq 0x2d280
callq 0x2c0c0
xorl %edi, %edi
callq 0x100f0
xorl %eax, %eax
addq $0x10, %rsp
popq %rbp
retq