// File: jkingan[P]ladyheather/heathgps.cpp
// Function: set_x72_dds(double)
void set_x72_dds(double val)
{
#define MAX_DDS_STEP  4.0E-8
#define MAX_DDS_RANGE 1.0E-6
double dval;
double set_val;
double sign;
int i, j;

   // set the X72 DDS freq tune value
   if(read_only) return;

   if(fabs(val) > 1.0E-6) return;

   if(val < 0.0) sign = (-1.0);
   else          sign = 1.0;

   last_x72_dds = val;
   user_set_x72_dds = 1;
   save_x72_state();

   dval = fabs(val);
   if(dval > MAX_DDS_RANGE) return;  // freq change is too large
   j = (int) (MAX_DDS_RANGE / MAX_DDS_STEP) + 1;

   set_val = 0.0;
   for(i=0; i<j; i++) {  // max DDS change allowed in one step is 4.0E-8
      if(dval > MAX_DDS_STEP) set_val += MAX_DDS_STEP;
      else                    set_val += dval;

      osc_offset = set_val*sign;

      val = set_val / 1.0E-12;  // we get E-12 steps
      have_osc_offset = 333;
      val = val / 10.0;     // scale E-12 input to E-11 
      sprintf(out, "f%.2f", val*sign);
      queue_x72_cmd(out, X72_SET_DDS_MSG);

      dval -= MAX_DDS_STEP;
      if(dval <= 0.0) break;
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movsd %xmm0, -0x8(%rbp)
leaq 0x2fbcf6(%rip), %rax    # 0x3961fa
cmpb $0x0, (%rax)
je 0x9a50e
jmp 0x9a6ae
movsd -0x8(%rbp), %xmm0
movaps 0xd4d76(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd 0xd7212(%rip), %xmm1    # 0x171738
ucomisd %xmm1, %xmm0
jbe 0x9a531
jmp 0x9a6ae
xorps %xmm0, %xmm0
ucomisd -0x8(%rbp), %xmm0
jbe 0x9a54a
movsd 0xd4bd5(%rip), %xmm0    # 0x16f118
movsd %xmm0, -0x20(%rbp)
jmp 0x9a557
movsd 0xd4b16(%rip), %xmm0    # 0x16f068
movsd %xmm0, -0x20(%rbp)
movsd -0x8(%rbp), %xmm0
leaq 0x1dfb5d(%rip), %rax    # 0x27a0c0
movsd %xmm0, (%rax)
leaq 0x1dfb22(%rip), %rax    # 0x27a090
movl $0x1, (%rax)
callq 0x92e20
movsd -0x8(%rbp), %xmm0
movaps 0xd4d0b(%rip), %xmm1    # 0x16f290
pand %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0xd719d(%rip), %xmm1    # 0x171738
ucomisd %xmm1, %xmm0
jbe 0x9a5a6
jmp 0x9a6ae
movl $0x1a, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x9a6ae
movsd -0x10(%rbp), %xmm0
movsd 0xe861b(%rip), %xmm1    # 0x182bf0
ucomisd %xmm1, %xmm0
jbe 0x9a5ef
movsd 0xe860d(%rip), %xmm0    # 0x182bf0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x9a5fe
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
leaq 0x2d1391(%rip), %rax    # 0x36b9a0
movsd %xmm0, (%rax)
movsd -0x18(%rbp), %xmm0
movsd 0xe85d8(%rip), %xmm1    # 0x182bf8
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
leaq 0x2d1de4(%rip), %rax    # 0x36c414
movl $0x14d, (%rax)          # imm = 0x14D
movsd -0x8(%rbp), %xmm0
movsd 0xd4a7d(%rip), %xmm1    # 0x16f0c0
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
mulsd -0x20(%rbp), %xmm0
leaq 0x300da3(%rip), %rdi    # 0x39b400
leaq 0xecbb1(%rip), %rsi     # 0x187215
movb $0x1, %al
callq 0x9060
leaq 0x300d8e(%rip), %rdi    # 0x39b400
movl $0x2bd, %esi            # imm = 0x2BD
callq 0x82fd0
movsd -0x10(%rbp), %xmm0
movsd 0xe8567(%rip), %xmm1    # 0x182bf0
subsd %xmm1, %xmm0
movsd %xmm0, -0x10(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x10(%rbp), %xmm0
jb 0x9a69e
jmp 0x9a6ae
jmp 0x9a6a0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x9a5bc
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)