// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_lathe_diameter_mode(int, block_struct*, setup_struct*)
int Interp::convert_lathe_diameter_mode(int g_code,    //!< g_code being executed (must be G_90_1 or G_91_1)
                  block_pointer block,           //!< pointer to current block
                  setup_pointer settings)        //!< pointer to machine settings
{
  if (g_code == G_7) {
    if (settings->lathe_diameter_mode != ON) {
      if(block->x_flag)
      {
        block->x_number /= 2; //Apply scaling now
      }
      if(block->motion_to_be == G_76) {
          block->i_number /= 2;
          block->j_number /= 2;
          block->k_number /= 2;
      }              
#ifdef DEBUG_EMC
      COMMENT("interpreter: Lathe diameter mode changed to diameter");
#endif
      settings->lathe_diameter_mode = ON;
    }
  } else if (g_code == G_8) {
    if (settings->lathe_diameter_mode != OFF) {
      if(block->x_flag)
      {
        block->x_number *= 2; //Remove any existing scaling
      }
      if(block->motion_to_be == G_76) {
          block->i_number *= 2;
          block->j_number *= 2;
          block->k_number *= 2;
      }              
#ifdef DEBUG_EMC
      COMMENT("interpreter: Lathe diameter mode changed to radius");
#endif
      settings->lathe_diameter_mode = OFF;
    }
  } else
    ERS("BUG: Code not G7 or G8");
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x46, -0x14(%rbp)
jne 0x2145a
movq -0x28(%rbp), %rax
movb 0x1e6d8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
je 0x21455
movq -0x20(%rbp), %rax
testb $0x1, 0x270(%rax)
je 0x213ce
movq -0x20(%rbp), %rax
movsd 0x278(%rax), %xmm0
movsd 0x55c46(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, 0x278(%rax)
movq -0x20(%rbp), %rax
cmpl $0x2f8, 0x1d8(%rax)     # imm = 0x2F8
jne 0x2143e
movq -0x20(%rbp), %rax
movsd 0x1a0(%rax), %xmm0
movsd 0x55c16(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, 0x1a0(%rax)
movq -0x20(%rbp), %rax
movsd 0x1b0(%rax), %xmm0
movsd 0x55bf6(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, 0x1b0(%rax)
movq -0x20(%rbp), %rax
movsd 0x1c0(%rax), %xmm0
movsd 0x55bd6(%rip), %xmm1    # 0x77008
divsd %xmm1, %xmm0
movsd %xmm0, 0x1c0(%rax)
leaq 0x58d7e(%rip), %rdi     # 0x7a1c3
callq 0x10d60
movq -0x28(%rbp), %rax
movb $0x1, 0x1e6d8(%rax)
jmp 0x215f1
cmpl $0x50, -0x14(%rbp)
jne 0x21525
movq -0x28(%rbp), %rax
movb 0x1e6d8(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x21520
movq -0x20(%rbp), %rax
testb $0x1, 0x270(%rax)
je 0x214a5
movq -0x20(%rbp), %rax
movsd 0x55b73(%rip), %xmm0    # 0x77008
mulsd 0x278(%rax), %xmm0
movsd %xmm0, 0x278(%rax)
movq -0x20(%rbp), %rax
cmpl $0x2f8, 0x1d8(%rax)     # imm = 0x2F8
jne 0x21509
movq -0x20(%rbp), %rax
movsd 0x55b47(%rip), %xmm0    # 0x77008
mulsd 0x1a0(%rax), %xmm0
movsd %xmm0, 0x1a0(%rax)
movq -0x20(%rbp), %rax
movsd 0x55b2b(%rip), %xmm0    # 0x77008
mulsd 0x1b0(%rax), %xmm0
movsd %xmm0, 0x1b0(%rax)
movq -0x20(%rbp), %rax
movsd 0x55b0f(%rip), %xmm0    # 0x77008
mulsd 0x1c0(%rax), %xmm0
movsd %xmm0, 0x1c0(%rax)
leaq 0x58ce8(%rip), %rdi     # 0x7a1f8
callq 0x10d60
movq -0x28(%rbp), %rax
movb $0x0, 0x1e6d8(%rax)
jmp 0x215ef
jmp 0x21527
movq -0x30(%rbp), %rdi
leaq 0x58cf9(%rip), %rsi     # 0x7a22b
movb $0x0, %al
callq 0x10df0
movq 0x65a20(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x65a0f(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x65a01(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x58cce(%rip), %rsi     # 0x7a242
movl $0x50, %edx
callq 0x10840
movq 0x659db(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x659cd(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x659b5(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x659a5(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x65998(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x6598a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x215f8
jmp 0x215f1
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)