// File: jkingan[P]ladyheather/heathui.cpp
// Function: edit_osc_pid_value(char, char*, int)
u08 edit_osc_pid_value(char c, char *s, int kbd_cmd)
{
   if(s == 0) return 'b';
   c = toupper(c);

   if((c == 'A') || (c == 'B')) {    // BA command - bang-bang autotune
   }
   else if(c == 'C') { // BC command - failed cable delay trick - does not work
      sscanf(s, "%lf", &trick_scale);
      if(trick_scale == 0.0) {
         set_pps(user_pps_enable, pps_polarity,  delay_value, pps1_delay, pps_threshold, 0);
         request_pps_info();
      }
      else {
         first_trick = 1;
         trick_value = 0.0;
      }
   }
   else if(c == 'D') {  // BD command - derivitive time constant
      sscanf(s, "%lf", &OSC_D_TC);
      calc_osc_k_factors();
   }
   else if(c == 'F') {  // BF command - filter time constant
      sscanf(s, "%lf", &OSC_FILTER_TC);
      calc_osc_k_factors();
   }
   else if(c == 'H') {  // BH command - PID debug (help) display
      osc_pid_debug = toggle_value(osc_pid_debug);
      if(osc_pid_debug) pid_debug = 0;
      if(kbd_cmd) clear_osc_pid_display();
   }
   else if(c == 'I') {  // BI command - integral time constant
      sscanf(s, "%lf", &OSC_I_TC);
      calc_osc_k_factors();
   }
   else if(c == 'K') {  // BK command - all major PID values
      OSC_FILTER_OFFSET = 0.0F;
      sscanf(s, "%lf%c%lf%c%lf%c%lf", &OSC_P_GAIN,&c, &OSC_D_TC,&c,  &OSC_FILTER_TC,&c, &OSC_I_TC);
      calc_osc_k_factors();
      if(kbd_cmd) enable_osc_control();
      if(0 && kbd_cmd) show_osc_pid_values();
   }
   else if(c == 'L') {  // BL command - load distubance
      sscanf(s, "%lf", &osc_k6);
      calc_osc_k_factors();
   }
   else if(c == 'N') {  // BN command - mark's values
      set_default_osc_pid(1);
      if(kbd_cmd) enable_osc_control();
      if(0 && kbd_cmd) show_osc_pid_values();
   }
   else if(c == 'O') {  // BO command - filter offset
      sscanf(s, "%lf", &OSC_FILTER_OFFSET);
      calc_osc_k_factors();
   }
   else if(c == 'P') {  // BP command - pid gain
      sscanf(s, "%lf", &OSC_P_GAIN);
      calc_osc_k_factors();
   }
   else if(c == 'Q') {  // BQ command - post-filter depth
//    sscanf(s, "%lf", &OSC_KL_TUNE_STEP);
//    sscanf(s, "%d", &osc_prefilter);
//    if(osc_prefilter > PRE_Q_SIZE) osc_prefilter = PRE_Q_SIZE;
//    opq_in = opq_count = 0;
      sscanf(s, "%d", &osc_postfilter);
      if(osc_postfilter > POST_Q_SIZE) osc_postfilter = POST_Q_SIZE;
      new_postfilter();
      calc_osc_k_factors();
   }
   else if(c == 'R') {  // BR command - integrator reset
      sscanf(s, "%lf", &osc_k8);
      calc_osc_k_factors();
   }
   else if(c == 'S') {  // BS command - scale factor (loop gain correction)
      sscanf(s, "%lf", &osc_k7);
      calc_osc_k_factors();
   }
   else if(c == 'W') {  // BW command - Warren's slow values
      set_default_osc_pid(0);
      if(kbd_cmd) enable_osc_control();
      if(0 && kbd_cmd) show_osc_pid_values();
   }
   else if(c == 'X') {  // BX command - John's values
      set_default_osc_pid(2);
      if(kbd_cmd) enable_osc_control();
      if(0 && kbd_cmd) show_osc_pid_values();
   }
   else if(c == 'Y') {  // BY command - TBD values
      set_default_osc_pid(3);
      if(kbd_cmd) enable_osc_control();
      if(0 && kbd_cmd) show_osc_pid_values();
   }
   else if(c == 'Z') {  // BZ command - reset PID
      reset_osc_pid(kbd_cmd);
   }
   else if(c == '0') {  // B0 command - turn off pid
      disable_osc_control();
   }
   else if(c == '1') {  // B1 command - turn pid on
      enable_osc_control();
   }
   else return 1;

   return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movb %dil, %al
movb %al, -0x2(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x492f5
movb $0x62, -0x1(%rbp)
jmp 0x49709
movsbl -0x2(%rbp), %edi
callq 0x96e0
movb %al, -0x2(%rbp)
movsbl -0x2(%rbp), %eax
cmpl $0x41, %eax
je 0x49313
movsbl -0x2(%rbp), %eax
cmpl $0x42, %eax
jne 0x49318
jmp 0x49705
movsbl -0x2(%rbp), %eax
cmpl $0x43, %eax
jne 0x493bb
movq -0x10(%rbp), %rdi
leaq 0x14caa8(%rip), %rsi    # 0x195dd8
leaq 0x3555c1(%rip), %rdx    # 0x39e8f8
movb $0x0, %al
callq 0x9370
leaq 0x3555b3(%rip), %rax    # 0x39e8f8
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x4939b
jp 0x4939b
leaq 0x323ba6(%rip), %rax    # 0x36cf01
movb (%rax), %cl
leaq 0x323b94(%rip), %rax    # 0x36cef8
movl (%rax), %eax
leaq 0x323c33(%rip), %rdx    # 0x36cfa0
movsd (%rdx), %xmm0
leaq 0x323c40(%rip), %rdx    # 0x36cfb8
movsd (%rdx), %xmm1
leaq 0x323b79(%rip), %rdx    # 0x36cefc
movss (%rdx), %xmm2
xorl %edx, %edx
movzbl %cl, %edi
movzbl %al, %esi
callq 0x91b20
callq 0x91720
jmp 0x493b6
leaq 0x35555e(%rip), %rax    # 0x39e900
movl $0x1, (%rax)
leaq 0x355559(%rip), %rax    # 0x39e908
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
jmp 0x49703
movsbl -0x2(%rbp), %eax
cmpl $0x44, %eax
jne 0x493e7
movq -0x10(%rbp), %rdi
leaq 0x14ca09(%rip), %rsi    # 0x195dd8
leaq 0x3554b2(%rip), %rdx    # 0x39e888
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x49701
movsbl -0x2(%rbp), %eax
cmpl $0x46, %eax
jne 0x49413
movq -0x10(%rbp), %rdi
leaq 0x14c9dd(%rip), %rsi    # 0x195dd8
leaq 0x35548e(%rip), %rdx    # 0x39e890
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496ff
movsbl -0x2(%rbp), %eax
cmpl $0x48, %eax
jne 0x4945c
leaq 0x355455(%rip), %rax    # 0x39e878
movzbl (%rax), %edi
callq 0x49220
movb %al, %cl
leaq 0x355444(%rip), %rax    # 0x39e878
movb %cl, (%rax)
leaq 0x35543b(%rip), %rax    # 0x39e878
cmpb $0x0, (%rax)
je 0x4944c
leaq 0x3553d7(%rip), %rax    # 0x39e820
movb $0x0, (%rax)
cmpl $0x0, -0x14(%rbp)
je 0x49457
callq 0x492a0
jmp 0x496fd
movsbl -0x2(%rbp), %eax
cmpl $0x49, %eax
jne 0x49488
movq -0x10(%rbp), %rdi
leaq 0x14c968(%rip), %rsi    # 0x195dd8
leaq 0x355421(%rip), %rdx    # 0x39e898
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496fb
movsbl -0x2(%rbp), %eax
cmpl $0x4b, %eax
jne 0x494fa
leaq 0x355408(%rip), %rax    # 0x39e8a0
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rdi
leaq 0x14cab9(%rip), %rsi    # 0x195f63
leaq 0x3553cf(%rip), %rdx    # 0x39e880
leaq -0x2(%rbp), %r10
leaq 0x3553cc(%rip), %r8     # 0x39e888
leaq 0x3553cd(%rip), %r11    # 0x39e890
leaq 0x3553ce(%rip), %rax    # 0x39e898
movq %r10, %rcx
movq %r10, %r9
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x9370
callq 0x16af10
cmpl $0x0, -0x14(%rbp)
je 0x494f5
callq 0x16be20
jmp 0x496f9
movsbl -0x2(%rbp), %eax
cmpl $0x4c, %eax
jne 0x49526
movq -0x10(%rbp), %rdi
leaq 0x14c8ca(%rip), %rsi    # 0x195dd8
leaq 0x46b95b(%rip), %rdx    # 0x4b4e70
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496f7
movsbl -0x2(%rbp), %eax
cmpl $0x4e, %eax
jne 0x49549
movl $0x1, %edi
callq 0x16b440
cmpl $0x0, -0x14(%rbp)
je 0x49544
callq 0x16be20
jmp 0x496f5
movsbl -0x2(%rbp), %eax
cmpl $0x4f, %eax
jne 0x49575
movq -0x10(%rbp), %rdi
leaq 0x14c87b(%rip), %rsi    # 0x195dd8
leaq 0x35533c(%rip), %rdx    # 0x39e8a0
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496f3
movsbl -0x2(%rbp), %eax
cmpl $0x50, %eax
jne 0x495a1
movq -0x10(%rbp), %rdi
leaq 0x14c84f(%rip), %rsi    # 0x195dd8
leaq 0x3552f0(%rip), %rdx    # 0x39e880
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496f1
movsbl -0x2(%rbp), %eax
cmpl $0x51, %eax
jne 0x495ee
movq -0x10(%rbp), %rdi
leaq 0x13dc8c(%rip), %rsi    # 0x187241
leaq 0x3552b0(%rip), %rdx    # 0x39e86c
movb $0x0, %al
callq 0x9370
leaq 0x3552a2(%rip), %rax    # 0x39e86c
cmpl $0x258, (%rax)          # imm = 0x258
jle 0x495df
leaq 0x355293(%rip), %rax    # 0x39e86c
movl $0x258, (%rax)          # imm = 0x258
callq 0x16b380
callq 0x16af10
jmp 0x496ef
movsbl -0x2(%rbp), %eax
cmpl $0x52, %eax
jne 0x4961a
movq -0x10(%rbp), %rdi
leaq 0x14c7d6(%rip), %rsi    # 0x195dd8
leaq 0x46b877(%rip), %rdx    # 0x4b4e80
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496ed
movsbl -0x2(%rbp), %eax
cmpl $0x53, %eax
jne 0x49646
movq -0x10(%rbp), %rdi
leaq 0x14c7aa(%rip), %rsi    # 0x195dd8
leaq 0x46b843(%rip), %rdx    # 0x4b4e78
movb $0x0, %al
callq 0x9370
callq 0x16af10
jmp 0x496eb
movsbl -0x2(%rbp), %eax
cmpl $0x57, %eax
jne 0x49666
xorl %edi, %edi
callq 0x16b440
cmpl $0x0, -0x14(%rbp)
je 0x49661
callq 0x16be20
jmp 0x496e9
movsbl -0x2(%rbp), %eax
cmpl $0x58, %eax
jne 0x49686
movl $0x2, %edi
callq 0x16b440
cmpl $0x0, -0x14(%rbp)
je 0x49684
callq 0x16be20
jmp 0x496e7
movsbl -0x2(%rbp), %eax
cmpl $0x59, %eax
jne 0x496a6
movl $0x3, %edi
callq 0x16b440
cmpl $0x0, -0x14(%rbp)
je 0x496a4
callq 0x16be20
jmp 0x496e5
movsbl -0x2(%rbp), %eax
cmpl $0x5a, %eax
jne 0x496b9
movl -0x14(%rbp), %edi
callq 0x16b300
jmp 0x496e3
movsbl -0x2(%rbp), %eax
cmpl $0x30, %eax
jne 0x496c9
callq 0x169390
jmp 0x496e1
movsbl -0x2(%rbp), %eax
cmpl $0x31, %eax
jne 0x496d9
callq 0x16be20
jmp 0x496df
movb $0x1, -0x1(%rbp)
jmp 0x49709
jmp 0x496e1
jmp 0x496e3
jmp 0x496e5
jmp 0x496e7
jmp 0x496e9
jmp 0x496eb
jmp 0x496ed
jmp 0x496ef
jmp 0x496f1
jmp 0x496f3
jmp 0x496f5
jmp 0x496f7
jmp 0x496f9
jmp 0x496fb
jmp 0x496fd
jmp 0x496ff
jmp 0x49701
jmp 0x49703
jmp 0x49705
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)