// File: jkingan[P]ladyheather/heathmsc.cpp
// Function: label_adev_grid(int)
void label_adev_grid(int top)
{
int row, col;
int row_step;
int top_row;
int i,j;
int k;
double val;
double range;
double steps;
int adev_top_row;   // calculate where the adev decades are in the plot area
int vert_scale;
int vert_ofs;
long m;

   if(all_adevs == SINGLE_ADEVS) {
      if(plot_adev_data == 0) return;   // no adevs on screen, don't label the plots
   }
   if(plot_adev_data == 0) return;   // no adevs on screen, don't label the plots

   graphics_coords = 1;

   m = 1L;
   for(i=0; i<first_show_bin; i++) {  // find tau of the first displayed bin
      if(ATYPE == A_MTIE) m *= 2;
      else                m = next_tau(m, bin_scale);
   }

   i = k = 0;
   adev_decades_shown = 0;
   for(col=0; col<PLOT_WIDTH; col+=HORIZ_MAJOR) {  // aaaaaapppppp
//      sprintf(out, "%ld", m);
      sprintf(out, "%g", adev_period * (double) m);

      if(col == 0) j = 0;
      else         j = (strlen(out)*TEXT_WIDTH) / 2;

      if((col-j) > (PLOT_WIDTH-(HORIZ_MAJOR*2))) break;
      else if((HORIZ_MAJOR < (6*TEXT_WIDTH)) && (k != 0)) ;
      else {
         vidstr(PLOT_ROW+2, 1+PLOT_COL+col-j, ADEV_LABEL_COLOR, out); // xyzzy
      }
      ++adev_decades_shown;

      k = (k + 1) % 3;
      if(ATYPE == A_MTIE) m *= 2;
      else                m = next_tau(m, bin_scale);
      if(m > 100000) break;
   }

   range = 0.0;
   val = 1.0;
   for(i=0; i<20; i++) {  // find decade value of the largest xDEV value
      if(global_adev_max >= val) break;
      val /= 10.0;
   }
   val *= 10.0;

   top_row = PLOT_ROW; // top;
   vert_scale = (PLOT_HEIGHT / (VERT_MAJOR*2)) * (VERT_MAJOR*2);  // two major divisions per decade
   vert_ofs = (PLOT_HEIGHT - vert_scale) / 2;
   if(((PLOT_HEIGHT / (VERT_MAJOR*2)) & 0x01) == 0x00) {  // align adevs to cyan dotted lines
      vert_ofs += VERT_MAJOR;
   }
   adev_top_row = PLOT_ROW + vert_ofs;
   if(adev_top_row && (adev_top_row > top_row)) top_row = adev_top_row;
//sprintf(debug_text, "plot:%d  top:%d  hmajor:%d  verts:%d  atr:%d  gam:%g  val:%g", PLOT_ROW, top, HORIZ_MAJOR, PLOT_HEIGHT/VERT_MAJOR, adev_top_row, global_adev_max, val);

   row_step = VERT_MAJOR;
   if(SCREEN_HEIGHT > SHORT_SCREEN) {
      row_step *= 2;
   }
   else if(zoom_screen == 'P') {  // aaaahhhh
      row_step *= 2;
   }
   adev_decade_height = (double) row_step;

   if(ATYPE == A_MTIE) {  // calculate vertical scale
      steps = 0.0;
      for(row=top_row; row<SCREEN_HEIGHT; row+=row_step) {
         steps += 1.0;
      }
      val = global_adev_max * MTIE_SCALE;
      range = val - (global_adev_min / MTIE_SCALE);
      if(steps) range /= steps;
   //sprintf(debug_text, "steps:%g", steps);
   }

   for(row=top_row; row<SCREEN_HEIGHT; row+=row_step) {
      if(ATYPE == A_MTIE) {
         sprintf(out, "%.3g", val);   // aaahhh %le
         val -= range;
      }
      else {
         sprintf(out, "%g", val);   // aaahhh %le
         val /= 10.0;
      }

      i = (strlen(out)+1) * TEXT_WIDTH;
      if((row == top_row) && (PLOT_ROW == adev_top_row)) {
         vidstr(row+2, PLOT_COL+PLOT_WIDTH-i, ADEV_LABEL_COLOR, out);
      }
      else {
         vidstr(row-TEXT_HEIGHT/2, PLOT_COL+PLOT_WIDTH-i, ADEV_LABEL_COLOR, out);
      }
   }

   bottom_adev_decade = (float) val;
   graphics_coords = 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x4(%rbp)
leaq 0x13c63c(%rip), %rax    # 0x29bf1e
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x15f900
leaq 0x11acc8(%rip), %rax    # 0x27a5b9
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x15f8fe
jmp 0x15fe3f
jmp 0x15f900
leaq 0x11acb2(%rip), %rax    # 0x27a5b9
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x15f914
jmp 0x15fe3f
leaq 0x11812d(%rip), %rax    # 0x277a48
movb $0x1, (%rax)
movq $0x1, -0x50(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
leaq 0x13c529(%rip), %rcx    # 0x29be60
cmpl (%rcx), %eax
jge 0x15f977
leaq 0x122eae(%rip), %rax    # 0x2827f0
cmpl $0x9, (%rax)
jne 0x15f954
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x15f96a
movq -0x50(%rbp), %rdi
leaq 0x13c4fd(%rip), %rax    # 0x29be5c
movl (%rax), %esi
callq 0x15e920
movq %rax, -0x50(%rbp)
jmp 0x15f96c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x15f92d
movl $0x0, -0x20(%rbp)
movl $0x0, -0x18(%rbp)
leaq 0x118018(%rip), %rax    # 0x2779a4
movl $0x0, (%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
leaq 0x1180c1(%rip), %rcx    # 0x277a64
cmpl (%rcx), %eax
jge 0x15faf0
leaq 0x13c526(%rip), %rax    # 0x29bed8
movsd (%rax), %xmm0
cvtsi2sdq -0x50(%rbp), %xmm1
mulsd %xmm1, %xmm0
leaq 0x23ba39(%rip), %rdi    # 0x39b400
leaq 0x32605(%rip), %rsi     # 0x191fd3
movb $0x1, %al
callq 0x9060
cmpl $0x0, -0xc(%rbp)
jne 0x15f9e4
movl $0x0, -0x1c(%rbp)
jmp 0x15fa04
leaq 0x23ba15(%rip), %rdi    # 0x39b400
callq 0x9120
leaq 0x117ff9(%rip), %rcx    # 0x2779f0
movslq (%rcx), %rcx
imulq %rcx, %rax
shrq %rax
movl %eax, -0x1c(%rbp)
movl -0xc(%rbp), %eax
subl -0x1c(%rbp), %eax
leaq 0x118053(%rip), %rcx    # 0x277a64
movl (%rcx), %ecx
leaq 0x11803a(%rip), %rdx    # 0x277a54
movl (%rdx), %edx
shll %edx
subl %edx, %ecx
cmpl %ecx, %eax
jle 0x15fa29
jmp 0x15faf0
leaq 0x118024(%rip), %rax    # 0x277a54
movl (%rax), %eax
leaq 0x117fb7(%rip), %rcx    # 0x2779f0
imull $0x6, (%rcx), %ecx
cmpl %ecx, %eax
jge 0x15fa48
cmpl $0x0, -0x20(%rbp)
je 0x15fa48
jmp 0x15fa77
leaq 0x11800d(%rip), %rax    # 0x277a5c
movl (%rax), %edi
addl $0x2, %edi
leaq 0x118005(%rip), %rax    # 0x277a60
movl (%rax), %esi
addl $0x1, %esi
addl -0xc(%rbp), %esi
subl -0x1c(%rbp), %esi
movl $0xa, %edx
leaq 0x23b98e(%rip), %rcx    # 0x39b400
callq 0x10ee0
jmp 0x15fa79
leaq 0x117f24(%rip), %rax    # 0x2779a4
movl (%rax), %ecx
addl $0x1, %ecx
leaq 0x117f18(%rip), %rax    # 0x2779a4
movl %ecx, (%rax)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %edx, -0x20(%rbp)
leaq 0x122d4a(%rip), %rax    # 0x2827f0
cmpl $0x9, (%rax)
jne 0x15fab8
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x50(%rbp)
jmp 0x15face
movq -0x50(%rbp), %rdi
leaq 0x13c399(%rip), %rax    # 0x29be5c
movl (%rax), %esi
callq 0x15e920
movq %rax, -0x50(%rbp)
cmpq $0x186a0, -0x50(%rbp)   # imm = 0x186A0
jle 0x15fada
jmp 0x15faf0
jmp 0x15fadc
leaq 0x117f71(%rip), %rax    # 0x277a54
movl (%rax), %eax
addl -0xc(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0x15f999
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0xf568(%rip), %xmm0     # 0x16f068
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x18(%rbp)
cmpl $0x14, -0x18(%rbp)
jge 0x15fb47
leaq 0x13c1af(%rip), %rax    # 0x29bcc8
movsd (%rax), %xmm0
ucomisd -0x28(%rbp), %xmm0
jb 0x15fb26
jmp 0x15fb47
movsd -0x28(%rbp), %xmm0
movsd 0xf58d(%rip), %xmm1     # 0x16f0c0
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x15fb0c
movsd 0xf571(%rip), %xmm0     # 0x16f0c0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
leaq 0x117efc(%rip), %rax    # 0x277a5c
movl (%rax), %eax
movl %eax, -0x14(%rbp)
leaq 0x117efc(%rip), %rax    # 0x277a68
movl (%rax), %eax
leaq 0x117ed7(%rip), %rcx    # 0x277a4c
movl (%rcx), %ecx
shll %ecx
cltd
idivl %ecx
leaq 0x117ec9(%rip), %rcx    # 0x277a4c
movl (%rcx), %ecx
shll %ecx
imull %ecx, %eax
movl %eax, -0x40(%rbp)
leaq 0x117ed4(%rip), %rax    # 0x277a68
movl (%rax), %eax
subl -0x40(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x44(%rbp)
leaq 0x117ebd(%rip), %rax    # 0x277a68
movl (%rax), %eax
leaq 0x117e98(%rip), %rcx    # 0x277a4c
movl (%rcx), %ecx
shll %ecx
cltd
idivl %ecx
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x15fbd2
leaq 0x117e82(%rip), %rax    # 0x277a4c
movl (%rax), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
leaq 0x117e83(%rip), %rax    # 0x277a5c
movl (%rax), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x15fbf5
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x15fbf5
movl -0x3c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq 0x117e50(%rip), %rax    # 0x277a4c
movl (%rax), %eax
movl %eax, -0x10(%rbp)
leaq 0x117ddc(%rip), %rax    # 0x2779e4
cmpl $0x258, (%rax)          # imm = 0x258
jle 0x15fc1a
movl -0x10(%rbp), %eax
shll %eax
movl %eax, -0x10(%rbp)
jmp 0x15fc33
leaq 0x20bd67(%rip), %rax    # 0x36b988
movzbl (%rax), %eax
cmpl $0x50, %eax
jne 0x15fc31
movl -0x10(%rbp), %eax
shll %eax
movl %eax, -0x10(%rbp)
jmp 0x15fc33
cvtsi2sdl -0x10(%rbp), %xmm0
leaq 0x13c291(%rip), %rax    # 0x29bed0
movsd %xmm0, (%rax)
leaq 0x122ba6(%rip), %rax    # 0x2827f0
cmpl $0x9, (%rax)
jne 0x15fcf0
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x117d79(%rip), %rcx    # 0x2779e4
cmpl (%rcx), %eax
jge 0x15fc8c
movsd 0xf3f1(%rip), %xmm0     # 0x16f068
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x10(%rbp), %eax
addl -0x8(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x15fc61
movsd 0x2f4bc(%rip), %xmm0    # 0x18f150
leaq 0x13c02d(%rip), %rax    # 0x29bcc8
mulsd (%rax), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
leaq 0x13c020(%rip), %rax    # 0x29bcd0
movsd (%rax), %xmm1
movsd 0x2f494(%rip), %xmm2    # 0x18f150
divsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x15fcdb
jp 0x15fcdb
jmp 0x15fcee
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x15fcf0
movl -0x14(%rbp), %eax
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %eax
leaq 0x117ce4(%rip), %rcx    # 0x2779e4
cmpl (%rcx), %eax
jge 0x15fe24
leaq 0x122ae1(%rip), %rax    # 0x2827f0
cmpl $0x9, (%rax)
jne 0x15fd43
movsd -0x28(%rbp), %xmm0
leaq 0x23b6e0(%rip), %rdi    # 0x39b400
leaq 0x38901(%rip), %rsi     # 0x198628
movb $0x1, %al
callq 0x9060
movsd -0x30(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
jmp 0x15fd73
movsd -0x28(%rbp), %xmm0
leaq 0x23b6b1(%rip), %rdi    # 0x39b400
leaq 0x3227d(%rip), %rsi     # 0x191fd3
movb $0x1, %al
callq 0x9060
movsd -0x28(%rbp), %xmm0
movsd 0xf356(%rip), %xmm1     # 0x16f0c0
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
leaq 0x23b686(%rip), %rdi    # 0x39b400
callq 0x9120
addq $0x1, %rax
leaq 0x117c66(%rip), %rcx    # 0x2779f0
movslq (%rcx), %rcx
imulq %rcx, %rax
movl %eax, -0x18(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x15fdd8
leaq 0x117cb9(%rip), %rax    # 0x277a5c
movl (%rax), %eax
cmpl -0x3c(%rbp), %eax
jne 0x15fdd8
movl -0x8(%rbp), %edi
addl $0x2, %edi
leaq 0x117ca9(%rip), %rax    # 0x277a60
movl (%rax), %esi
leaq 0x117ca4(%rip), %rax    # 0x277a64
addl (%rax), %esi
subl -0x18(%rbp), %esi
movl $0xa, %edx
leaq 0x23b62f(%rip), %rcx    # 0x39b400
callq 0x10ee0
jmp 0x15fe14
movl -0x8(%rbp), %edi
leaq 0x117c12(%rip), %rax    # 0x2779f4
movl (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
subl %eax, %edi
leaq 0x117c6b(%rip), %rax    # 0x277a60
movl (%rax), %esi
leaq 0x117c66(%rip), %rax    # 0x277a64
addl (%rax), %esi
subl -0x18(%rbp), %esi
movl $0xa, %edx
leaq 0x23b5f1(%rip), %rcx    # 0x39b400
callq 0x10ee0
jmp 0x15fe16
movl -0x10(%rbp), %eax
addl -0x8(%rbp), %eax
movl %eax, -0x8(%rbp)
jmp 0x15fcf6
movsd -0x28(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x2799c3(%rip)   # 0x3d97f8
leaq 0x117c0c(%rip), %rax    # 0x277a48
movb $0x0, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)