// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_tool_change(setup_struct*)
int Interp::convert_tool_change(setup_pointer settings)  //!< pointer to machine settings
{

  if (settings->selected_pocket < 0) {
    ERS(NCE_TXX_MISSING_FOR_M6);
  }

  CHKS((settings->cutter_comp_side != OFF),
       (_("Cannot change tools with cutter radius compensation on")));

  if (!settings->tool_change_with_spindle_on) {
      STOP_SPINDLE_TURNING();
      settings->spindle_turning = CANON_STOPPED;
  }

  if (settings->tool_change_quill_up) {
      double up_z;
      double discard;
      find_relative(0., 0., 0., 0., 0., 0., 0., 0., 0., 
                    &discard, &discard, &up_z,
                    &discard, &discard, &discard, 
                    &discard, &discard, &discard,
                    settings);
      COMMENT("AXIS,hide");
      STRAIGHT_TRAVERSE(-1, settings->current_x, settings->current_y, up_z,
                        settings->AA_current, settings->BB_current, settings->CC_current,
                        settings->u_current, settings->v_current, settings->w_current);
      COMMENT("AXIS,show");
      settings->current_z = up_z;
  }

  if (settings->tool_change_at_g30) {
      double end_x;
      double end_y;
      double end_z;
      double AA_end;
      double BB_end;
      double CC_end;
      double u_end;
      double v_end;
      double w_end;

      find_relative(USER_TO_PROGRAM_LEN(settings->parameters[5181]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5182]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5183]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5184]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5185]),
                    USER_TO_PROGRAM_ANG(settings->parameters[5186]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5187]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5188]),
                    USER_TO_PROGRAM_LEN(settings->parameters[5189]),
                    &end_x, &end_y, &end_z,
                    &AA_end, &BB_end, &CC_end, 
                    &u_end, &v_end, &w_end, settings);
      COMMENT("AXIS,hide");
      STRAIGHT_TRAVERSE(-1, end_x, end_y, end_z,
                        AA_end, BB_end, CC_end,
                        u_end, v_end, w_end);
      COMMENT("AXIS,show");
      settings->current_x = end_x;
      settings->current_y = end_y;
      settings->current_z = end_z;
      settings->AA_current = AA_end;
      settings->BB_current = BB_end;
      settings->CC_current = CC_end;
      settings->u_current = u_end;
      settings->v_current = v_end;
      settings->w_current = w_end;
  }

  CHANGE_TOOL(settings->selected_pocket);

  settings->current_pocket = settings->selected_pocket;
  // tool change can move the controlled point.  reread it:
  settings->toolchange_flag = ON; 
  set_tool_parameters();
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc6b0(%rax)
jge 0x29a5a
jmp 0x29984
leaq 0x519c4(%rip), %rdi     # 0x7b34f
callq 0x10380
movq -0x88(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x5d5b8(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x5d5a7(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x5d599(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x5199b(%rip), %rsi     # 0x7b377
movl $0x50, %edx
callq 0x10840
movq 0x5d573(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5d565(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5d54d(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5d53d(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x5d530(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5d522(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x14(%rbp)
jmp 0x2a34f
jmp 0x29a5c
movq -0x28(%rbp), %rax
cmpl $0x0, 0x624(%rax)
je 0x29b45
jmp 0x29a6f
leaq 0x51930(%rip), %rdi     # 0x7b3a6
callq 0x10380
movq -0x88(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x5d4cd(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x5d4bc(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x5d4ae(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x518b0(%rip), %rsi     # 0x7b377
movl $0x50, %edx
callq 0x10840
movq 0x5d488(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5d47a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5d462(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5d452(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x5d445(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5d437(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x14(%rbp)
jmp 0x2a34f
jmp 0x29b47
movq -0x28(%rbp), %rax
cmpl $0x0, 0x1e6c8(%rax)
jne 0x29b67
callq 0x11300
movq -0x28(%rbp), %rax
movl $0x1, 0xc6cc(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x1e6c4(%rax)
je 0x29c7f
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rax
xorps %xmm8, %xmm8
movsd %xmm8, -0x98(%rbp)
leaq -0x38(%rbp), %r10
movq %r10, -0x90(%rbp)
leaq -0x30(%rbp), %rcx
movaps %xmm8, %xmm0
movaps %xmm8, %xmm1
movaps %xmm8, %xmm2
movaps %xmm8, %xmm3
movaps %xmm8, %xmm4
movaps %xmm8, %xmm5
movaps %xmm8, %xmm6
movaps %xmm8, %xmm7
movsd %xmm8, (%rsp)
movq %r10, %rsi
movq %r10, %rdx
movq %r10, %r8
movq %r10, %r9
movq %r10, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x10630
leaq 0x517e7(%rip), %rdi     # 0x7b3dd
callq 0x10d60
movq -0x28(%rbp), %rax
movsd 0x600(%rax), %xmm0
movq -0x28(%rbp), %rax
movsd 0x608(%rax), %xmm1
movsd -0x30(%rbp), %xmm2
movq -0x28(%rbp), %rax
movsd 0x8(%rax), %xmm3
movq -0x28(%rbp), %rax
movsd 0x20(%rax), %xmm4
movq -0x28(%rbp), %rax
movsd 0x38(%rax), %xmm5
movq -0x28(%rbp), %rax
movsd 0x50(%rax), %xmm6
movq -0x28(%rbp), %rax
movsd 0x68(%rax), %xmm7
movq -0x28(%rbp), %rax
movsd 0x80(%rax), %xmm8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movsd %xmm8, (%rsp)
callq 0x10ef0
leaq 0x5177e(%rip), %rdi     # 0x7b3e7
callq 0x10d60
movsd -0x30(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x610(%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x1e6c0(%rax)
je 0x2a30e
movq -0x28(%rbp), %rax
movsd 0xb9a8(%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq 0x5d299(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x29ce2
movsd 0x4f170(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0xb0(%rbp)
jmp 0x29d34
movq 0x5d277(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4f149(%rip), %xmm0    # 0x78e40
movsd 0x4f111(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0xc0(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0xb8(%rbp)
je 0x29d24
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd -0xb0(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9b0(%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
movq 0x5d1d9(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x29da2
movsd 0x4f0b0(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0xe0(%rbp)
jmp 0x29df4
movq 0x5d1b7(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4f089(%rip), %xmm0    # 0x78e40
movsd 0x4f051(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0xf0(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0xe8(%rbp)
je 0x29de4
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd -0xe0(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x108(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9b8(%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movq 0x5d119(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x29e62
movsd 0x4eff0(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0x110(%rbp)
jmp 0x29eb4
movq 0x5d0f7(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4efc9(%rip), %xmm0    # 0x78e40
movsd 0x4ef91(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0x120(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0x118(%rbp)
je 0x29ea4
movsd -0x120(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd -0x118(%rbp), %xmm0
movsd %xmm0, -0x110(%rbp)
movsd -0xf8(%rbp), %xmm0
movsd -0x110(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x168(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9c0(%rax), %xmm0
movsd %xmm0, -0x160(%rbp)
callq 0x11920
movaps %xmm0, %xmm1
movsd -0x160(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x158(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9c8(%rax), %xmm0
movsd %xmm0, -0x150(%rbp)
callq 0x11920
movaps %xmm0, %xmm1
movsd -0x150(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x148(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9d0(%rax), %xmm0
movsd %xmm0, -0x140(%rbp)
callq 0x11920
movaps %xmm0, %xmm1
movsd -0x140(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x138(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9d8(%rax), %xmm0
movsd %xmm0, -0x130(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0x130(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x128(%rbp)
movq 0x5cfc9(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x29fb2
movsd 0x4eea0(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0x170(%rbp)
jmp 0x2a004
movq 0x5cfa7(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4ee79(%rip), %xmm0    # 0x78e40
movsd 0x4ee41(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0x180(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0x178(%rbp)
je 0x29ff4
movsd -0x180(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
movsd -0x128(%rbp), %xmm0
movsd -0x170(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x198(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9e0(%rax), %xmm0
movsd %xmm0, -0x190(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0x190(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x188(%rbp)
movq 0x5cf09(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x2a072
movsd 0x4ede0(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0x1a0(%rbp)
jmp 0x2a0c4
movq 0x5cee7(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4edb9(%rip), %xmm0    # 0x78e40
movsd 0x4ed81(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0x1b0(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0x1a8(%rbp)
je 0x2a0b4
movsd -0x1b0(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
movsd -0x1a8(%rbp), %xmm0
movsd %xmm0, -0x1a0(%rbp)
movsd -0x188(%rbp), %xmm0
movsd -0x1a0(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x1c8(%rbp)
movq -0x28(%rbp), %rax
movsd 0xb9e8(%rax), %xmm0
movsd %xmm0, -0x1c0(%rbp)
callq 0x11030
movaps %xmm0, %xmm1
movsd -0x1c0(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x1b8(%rbp)
movq 0x5ce49(%rip), %rax     # 0x86f60
cmpl $0x1, 0x1690(%rax)
jne 0x2a132
movsd 0x4ed20(%rip), %xmm0    # 0x78e48
movsd %xmm0, -0x1d0(%rbp)
jmp 0x2a184
movq 0x5ce27(%rip), %rax     # 0x86f60
movl 0x1690(%rax), %eax
movsd 0x4ecf9(%rip), %xmm0    # 0x78e40
movsd 0x4ecc1(%rip), %xmm1    # 0x78e10
movsd %xmm1, -0x1e0(%rbp)
cmpl $0x3, %eax
movsd %xmm0, -0x1d8(%rbp)
je 0x2a174
movsd -0x1e0(%rbp), %xmm0
movsd %xmm0, -0x1d8(%rbp)
movsd -0x1d8(%rbp), %xmm0
movsd %xmm0, -0x1d0(%rbp)
movsd -0x1c8(%rbp), %xmm7
movsd -0x198(%rbp), %xmm6
movsd -0x138(%rbp), %xmm5
movsd -0x148(%rbp), %xmm4
movsd -0x158(%rbp), %xmm3
movsd -0x168(%rbp), %xmm2
movsd -0x108(%rbp), %xmm1
movsd -0xd8(%rbp), %xmm0
movq -0x88(%rbp), %rdi
movsd -0x1b8(%rbp), %xmm8
movsd -0x1d0(%rbp), %xmm9
divsd %xmm9, %xmm8
movq -0x28(%rbp), %rax
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x58(%rbp), %r8
leaq -0x60(%rbp), %r9
leaq -0x68(%rbp), %r14
leaq -0x70(%rbp), %rbx
leaq -0x78(%rbp), %r11
leaq -0x80(%rbp), %r10
movsd %xmm8, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x10630
leaq 0x511a8(%rip), %rdi     # 0x7b3dd
callq 0x10d60
movsd -0x40(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd -0x50(%rbp), %xmm2
movsd -0x58(%rbp), %xmm3
movsd -0x60(%rbp), %xmm4
movsd -0x68(%rbp), %xmm5
movsd -0x70(%rbp), %xmm6
movsd -0x78(%rbp), %xmm7
movsd -0x80(%rbp), %xmm8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movsd %xmm8, (%rsp)
callq 0x10ef0
leaq 0x51168(%rip), %rdi     # 0x7b3e7
callq 0x10d60
movsd -0x40(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x600(%rax)
movsd -0x48(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x608(%rax)
movsd -0x50(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x610(%rax)
movsd -0x58(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd -0x60(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movsd -0x68(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movsd -0x70(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x50(%rax)
movsd -0x78(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movsd -0x80(%rbp), %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x28(%rbp), %rax
movl 0xc6b0(%rax), %edi
callq 0x104a0
movq -0x88(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0xc6b0(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x5fc(%rax)
movq -0x28(%rbp), %rax
movb $0x1, 0xc682(%rax)
callq 0x119a0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbx
popq %r14
popq %rbp
retq
nop