// File: jkingan[P]ladyheather/heather.cpp
// Function: do_plot_click(int)
void do_plot_click(int click)
{
static int mouse_sleeps = 0;
int right_button;
S32 i;

#define MOUSE_SLEEP  10    // msec delay between testing for next mouse state while right_click scrolling
#define SCROLL_SERVE 200   // serve_gps() every this many msecs while right_click scrolling

   // process a click in the plot area

   mouse_x -= PLOT_COL;
   if((mouse_x >= 0) && (mouse_x < plot_column) && (mouse_y >= PLOT_ROW) && (mouse_y < (PLOT_ROW+PLOT_HEIGHT))) { // mouse is in the plot area
//    show_last_mouse_x(WHITE);      // lmq
      last_plot_mouse_x = mouse_x;
      show_last_mouse_x(GREEN);      // lmq
      if(last_mouse_x != mouse_x) new_mouse_info |= 0x01;
      else if(last_mouse_y != mouse_y) new_mouse_info |= 0x01;

      i = plot_q_col0 + ((view_interval * mouse_x)/plot_mag);
      while(i >= plot_q_size) i -= plot_q_size;
      if(i != last_mouse_q) last_plot_glitch = i;  // mouse was moved
      last_mouse_q = last_plot_mouse_q = i;
      mouse_plot_valid = 1;  // mouse is in the plot area

      right_button = 2;
      if(touch_screen && button_lock) right_button = 1;  // change left button to right button

      if((this_button == right_button) && (last_button == 0)) {  // mark plot and center on it
         view_all_data = 0;
         need_view_auto = 0;
         right_time = 0;

         right_click:
         mark_q_entry[0] = last_mouse_q;  // mark the point

         no_mouse_review = 1; // inhibit recursive call to get_mouse_info
         goto_mark(0);        // center plot on the marked point
         no_mouse_review = 0;
      }
      else if((this_button == right_button) && (last_button == right_button)) {  // scroll plot with right mouse button
         Sleep(MOUSE_SLEEP);
         ++mouse_sleeps;

         // keep gps processing alive approx every 200 msecs while right mouse button scrolling
         if(enable_timer == 0) ;
         else if(timer_serve);
         else if((mouse_sleeps % (SCROLL_SERVE/MOUSE_SLEEP)) == 0) {
            #ifdef WINDOWS
               // windows timer proc does this for us
            #else
               ++timer_serve;
               serve_gps(55);
               --timer_serve;
            #endif  // __linux__  __MACH__   __FreeBSD__
         }

         if(++right_time >= RIGHT_DELAY) goto right_click;
      }
      else if(click) {  // zoom
         view_all_data = 0;
         need_view_auto = 0;
         right_time = 0;
         kbd_zoom();
      }
      else right_time = 0;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movl 0x250a7f(%rip), %ecx    # 0x277a60
movl 0x253439(%rip), %eax    # 0x27a420
subl %ecx, %eax
movl %eax, 0x253431(%rip)    # 0x27a420
cmpl $0x0, 0x25342a(%rip)    # 0x27a420
jl 0x2727f
movl 0x25341e(%rip), %eax    # 0x27a420
cmpl 0x2535a4(%rip), %eax    # 0x27a5ac
jge 0x2727f
movl 0x253410(%rip), %eax    # 0x27a424
cmpl 0x250a42(%rip), %eax    # 0x277a5c
jl 0x2727f
movl 0x2533fe(%rip), %eax    # 0x27a424
movl 0x250a30(%rip), %ecx    # 0x277a5c
addl 0x250a36(%rip), %ecx    # 0x277a68
cmpl %ecx, %eax
jge 0x2727f
movl 0x2533e0(%rip), %eax    # 0x27a420
movl %eax, 0x2533ea(%rip)    # 0x27a430
movl $0xa, %edi
callq 0x11b90
movl 0x25341a(%rip), %eax    # 0x27a470
cmpl 0x2533c4(%rip), %eax    # 0x27a420
je 0x27070
movzbl 0x2533d5(%rip), %eax    # 0x27a43a
orl $0x1, %eax
movb %al, 0x2533cc(%rip)     # 0x27a43a
jmp 0x27090
movl 0x2533fe(%rip), %eax    # 0x27a474
cmpl 0x2533a8(%rip), %eax    # 0x27a424
je 0x2708e
movzbl 0x2533b5(%rip), %eax    # 0x27a43a
orl $0x1, %eax
movb %al, 0x2533ac(%rip)     # 0x27a43a
jmp 0x27090
movq 0x2533b1(%rip), %rax    # 0x27a448
movq %rax, -0x18(%rbp)
movq 0x2534de(%rip), %rax    # 0x27a580
movslq 0x253377(%rip), %rcx    # 0x27a420
imulq %rcx, %rax
movslq 0x2534fc(%rip), %rcx    # 0x27a5b0
cqto
idivq %rcx
movq %rax, %rcx
movq -0x18(%rbp), %rax
addq %rcx, %rax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
cmpq 0x25342f(%rip), %rax    # 0x27a500
jl 0x270e6
movq 0x253426(%rip), %rcx    # 0x27a500
movslq -0xc(%rbp), %rax
subq %rcx, %rax
movl %eax, -0xc(%rbp)
jmp 0x270c6
movslq -0xc(%rbp), %rax
cmpq 0x253367(%rip), %rax    # 0x27a458
je 0x270fe
movslq -0xc(%rbp), %rax
movq %rax, 0x253362(%rip)    # 0x27a460
movslq -0xc(%rbp), %rax
movq %rax, 0x25335f(%rip)    # 0x27a468
movq %rax, 0x253348(%rip)    # 0x27a458
movb $0x1, 0x253321(%rip)    # 0x27a438
movl $0x2, -0x8(%rbp)
cmpb $0x0, 0x2532d9(%rip)    # 0x27a3fe
je 0x27137
cmpl $0x0, 0x378226(%rip)    # 0x39f354
je 0x27137
movl $0x1, -0x8(%rbp)
movl 0x2532ff(%rip), %eax    # 0x27a43c
cmpl -0x8(%rbp), %eax
jne 0x27195
cmpl $0x0, 0x2532f7(%rip)    # 0x27a440
jne 0x27195
movb $0x0, 0x253453(%rip)    # 0x27a5a5
movl $0x0, 0x253444(%rip)    # 0x27a5a0
movq $0x0, 0x274dc9(%rip) # 0x29bf30
movq 0x2532ea(%rip), %rax    # 0x27a458
movq %rax, 0x25331b(%rip)    # 0x27a490
movl $0x1, 0x377f59(%rip)    # 0x39f0d8
xorl %edi, %edi
callq 0x27290
movl $0x0, 0x377f48(%rip)    # 0x39f0d8
jmp 0x2727d
movl 0x2532a1(%rip), %eax    # 0x27a43c
cmpl -0x8(%rbp), %eax
jne 0x27245
movl 0x253296(%rip), %eax    # 0x27a440
cmpl -0x8(%rbp), %eax
jne 0x27245
movl $0xa, %edi
callq 0xb8b0
movl 0x378635(%rip), %eax    # 0x39f7f8
addl $0x1, %eax
movl %eax, 0x37862c(%rip)    # 0x39f7f8
movzbl 0x3460c9(%rip), %eax    # 0x36d29c
cmpl $0x0, %eax
jne 0x271da
jmp 0x27226
movl 0x253218(%rip), %eax    # 0x27a3f8
cmpl $0x0, %eax
je 0x271e7
jmp 0x27224
movl 0x37860b(%rip), %eax    # 0x39f7f8
movl $0x14, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x27222
movl 0x2531f8(%rip), %eax    # 0x27a3f8
addl $0x1, %eax
movl %eax, 0x2531ef(%rip)    # 0x27a3f8
movl $0x37, %edi
callq 0x27360
movl 0x2531df(%rip), %eax    # 0x27a3f8
addl $-0x1, %eax
movl %eax, 0x2531d6(%rip)    # 0x27a3f8
jmp 0x27224
jmp 0x27226
movq 0x274d03(%rip), %rax    # 0x29bf30
addq $0x1, %rax
movq %rax, 0x274cf8(%rip)    # 0x29bf30
cmpq $0xa, %rax
jl 0x27243
jmp 0x27167
jmp 0x2727b
cmpl $0x0, -0x4(%rbp)
je 0x2726e
movb $0x0, 0x253353(%rip)    # 0x27a5a5
movl $0x0, 0x253344(%rip)    # 0x27a5a0
movq $0x0, 0x274cc9(%rip) # 0x29bf30
callq 0x276a0
jmp 0x27279
movq $0x0, 0x274cb7(%rip) # 0x29bf30
jmp 0x2727b
jmp 0x2727d
jmp 0x2727f
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)