// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_control_mode(int, double, double, setup_struct*)
int Interp::convert_control_mode(int g_code,     //!< g_code being executed (G_61, G61_1, || G_64)
				double tolerance,    //tolerance for the path following in G64
				double naivecam_tolerance,    //tolerance for the naivecam
                                setup_pointer settings) //!< pointer to machine settings                 
{
  CHKS((settings->cutter_comp_side != OFF),
       (_("Cannot change control mode with cutter radius compensation on")));
  if (g_code == G_61) {
    SET_MOTION_CONTROL_MODE(CANON_EXACT_PATH, 0);
    settings->control_mode = CANON_EXACT_PATH;
  } else if (g_code == G_61_1) {
    SET_MOTION_CONTROL_MODE(CANON_EXACT_STOP, 0);
    settings->control_mode = CANON_EXACT_STOP;
  } else if (g_code == G_64) {
	if (tolerance >= 0) {
	    SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS, tolerance);
	} else {
	    SET_MOTION_CONTROL_MODE(CANON_CONTINUOUS, 0);
	}
	if (naivecam_tolerance >= 0) {
	    SET_NAIVECAM_TOLERANCE(naivecam_tolerance);
	} else if (tolerance >= 0) {
	    SET_NAIVECAM_TOLERANCE(tolerance);   // if no naivecam_tolerance specified use same for both
	} else {
	    SET_NAIVECAM_TOLERANCE(0);
	}
    settings->control_mode = CANON_CONTINUOUS;
  } else 
    ERS(NCE_BUG_CODE_NOT_G61_G61_1_OR_G64);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movsd %xmm0, -0x20(%rbp)
movsd %xmm1, -0x28(%rbp)
movq %rdx, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, 0x624(%rax)
je 0x1f1eb
jmp 0x1f118
leaq 0x5ab36(%rip), %rdi     # 0x79c55
callq 0x10380
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x67e27(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x67e16(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x67e08(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x5ab26(%rip), %rsi     # 0x79c93
movl $0x50, %edx
callq 0x10840
movq 0x67de2(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x67dd4(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x67dbc(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x67dac(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x67d9f(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x67d91(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x1f3a2
jmp 0x1f1ed
cmpl $0x262, -0x14(%rbp)     # imm = 0x262
jne 0x1f216
movl $0x2, %edi
xorps %xmm0, %xmm0
callq 0x10160
movq -0x30(%rbp), %rax
movl $0x2, 0x5f8(%rax)
jmp 0x1f39b
cmpl $0x263, -0x14(%rbp)     # imm = 0x263
jne 0x1f23f
movl $0x1, %edi
xorps %xmm0, %xmm0
callq 0x10160
movq -0x30(%rbp), %rax
movl $0x1, 0x5f8(%rax)
jmp 0x1f399
cmpl $0x280, -0x14(%rbp)     # imm = 0x280
jne 0x1f2c5
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f267
movsd -0x20(%rbp), %xmm0
movl $0x3, %edi
callq 0x10160
jmp 0x1f274
movl $0x3, %edi
xorps %xmm0, %xmm0
callq 0x10160
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f28e
movsd -0x28(%rbp), %xmm0
callq 0x10fc0
jmp 0x1f2b2
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1f2a8
movsd -0x20(%rbp), %xmm0
callq 0x10fc0
jmp 0x1f2b0
xorps %xmm0, %xmm0
callq 0x10fc0
jmp 0x1f2b2
movq -0x30(%rbp), %rax
movl $0x3, 0x5f8(%rax)
jmp 0x1f397
jmp 0x1f2c7
leaq 0x5aa0a(%rip), %rdi     # 0x79cd8
callq 0x10380
movq -0x38(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x67c78(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x67c67(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x67c59(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x5a977(%rip), %rsi     # 0x79c93
movl $0x50, %edx
callq 0x10840
movq 0x67c33(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x67c25(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x67c0d(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x67bfd(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x67bf0(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x67be2(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x1f3a2
jmp 0x1f399
jmp 0x1f39b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)