// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_probe(block_struct*, int, setup_struct*)
int Interp::convert_probe(block_pointer block,   //!< pointer to a block of RS274 instructions
                          int g_code,
                          setup_pointer settings)        //!< pointer to machine settings             
{
  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;

  /* probe_type: 
     ~1 = error if probe operation is unsuccessful (ngc default)
     |1 = suppress error, report in # instead
     ~2 = move until probe trips (ngc default)
     |2 = move until probe clears */

  unsigned char probe_type = g_code - G_38_2;
  

  CHKS((block->x_flag == OFF && block->y_flag == OFF &&
       block->z_flag == OFF && block->a_flag == OFF &&
       block->b_flag == OFF && block->c_flag == OFF &&
       block->u_flag == OFF && block->v_flag == OFF &&
       block->w_flag == OFF && block->radius_flag == OFF &&
       block->theta_flag == OFF),
       NCE_X_Y_Z_A_B_C_U_V_AND_W_WORDS_ALL_MISSING_WITH_G38_2);
  CHKS((settings->cutter_comp_side != OFF),
      NCE_CANNOT_PROBE_WITH_CUTTER_RADIUS_COMP_ON);
  CHKS((settings->feed_rate == 0.0), NCE_CANNOT_PROBE_WITH_ZERO_FEED_RATE);
  CHKS(settings->feed_mode == UNITS_PER_REVOLUTION,
	  "Cannot probe with feed per rev mode");
  CHKS((settings->feed_rate == 0.0), NCE_CANNOT_PROBE_WITH_ZERO_FEED_RATE);
  CHP(find_ends(block, settings, &end_x, &end_y, &end_z,
                &AA_end, &BB_end, &CC_end,
                &u_end, &v_end, &w_end));
  CHKS(((!(probe_type & 1)) && 
        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),
       NCE_START_POINT_TOO_CLOSE_TO_PROBE_POINT);
       
  TURN_PROBE_ON();
  STRAIGHT_PROBE(block->line_number, end_x, end_y, end_z,
                 AA_end, BB_end, CC_end,
                 u_end, v_end, w_end, probe_type);

  TURN_PROBE_OFF();
  settings->motion_mode = g_code;
  settings->probe_flag = ON;
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xb8, %rsp
movq %rdi, -0x28(%rbp)
movq %rsi, -0x30(%rbp)
movl %edx, -0x34(%rbp)
movq %rcx, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x34(%rbp), %eax
subl $0x17e, %eax            # imm = 0x17E
movb %al, -0x89(%rbp)
movq -0x30(%rbp), %rax
movb 0x270(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x280(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x290(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb (%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x10(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x244(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x250(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
movb 0x260(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x2e970
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2a0(%rax)
jne 0x2e970
movq -0x30(%rbp), %rax
cmpl $0x0, 0x2b0(%rax)
jne 0x2e970
jmp 0x2e89a
leaq 0x4c1fa(%rip), %rdi     # 0x7aa9b
callq 0x10380
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x586a2(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x58691(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x58683(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4c1e4(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x5865d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5864f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x58637(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x58627(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x5861a(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5860c(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2e972
jmp 0x2e974
movq -0x40(%rbp), %rax
cmpl $0x0, 0x624(%rax)
je 0x2ea5d
jmp 0x2e987
leaq 0x4c185(%rip), %rdi     # 0x7ab13
callq 0x10380
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x585b5(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x585a4(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x58596(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4c0f7(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x58570(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58562(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5854a(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5853a(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x5852d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5851f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2ea5f
jmp 0x2ea61
movq -0x40(%rbp), %rax
movsd 0x678(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2eb58
jp 0x2eb58
jmp 0x2ea82
leaq 0x4c0b2(%rip), %rdi     # 0x7ab3b
callq 0x10380
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x584ba(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x584a9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x5849b(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4bffc(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x58475(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58467(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5844f(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5843f(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x58432(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58424(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2eb5a
jmp 0x2eb5c
movq -0x40(%rbp), %rax
cmpl $0x2, 0x670(%rax)
jne 0x2ec3d
jmp 0x2eb6f
movq -0x98(%rbp), %rdi
leaq 0x4bfdf(%rip), %rsi     # 0x7ab5c
movb $0x0, %al
callq 0x10df0
movq 0x583d5(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x583c4(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x583b6(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4bf17(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x58390(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58382(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5836a(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5835a(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x5834d(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5833f(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2ec3f
jmp 0x2ec41
movq -0x40(%rbp), %rax
movsd 0x678(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2ed38
jp 0x2ed38
jmp 0x2ec62
leaq 0x4bed2(%rip), %rdi     # 0x7ab3b
callq 0x10380
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x582da(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x582c9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x582bb(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4be1c(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x58295(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58287(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x5826f(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x5825f(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x58252(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58244(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2ed3a
jmp 0x2ed3c
movq -0x98(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x48(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x58(%rbp), %r9
leaq -0x60(%rbp), %r15
leaq -0x68(%rbp), %r14
leaq -0x70(%rbp), %rbx
leaq -0x78(%rbp), %r11
leaq -0x80(%rbp), %r10
leaq -0x88(%rbp), %rax
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x11150
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0x2ee67
jmp 0x2eda9
movq 0x581b0(%rip), %rax     # 0x86f60
cmpl $0x31, 0xd670(%rax)
jge 0x2ee59
movq 0x5819c(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x5818e(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4bcef(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x58168(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x5815a(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x58142(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x58132(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x58125(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x58117(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl -0x90(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2ee69
jmp 0x2ee6b
movzbl -0x89(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x600(%rax), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x608(%rax), %xmm0
ucomisd -0x50(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x610(%rax), %xmm0
ucomisd -0x58(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x8(%rax), %xmm0
ucomisd -0x60(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x20(%rax), %xmm0
ucomisd -0x68(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x38(%rax), %xmm0
ucomisd -0x70(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x50(%rax), %xmm0
ucomisd -0x78(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x68(%rax), %xmm0
ucomisd -0x80(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
movq -0x40(%rbp), %rax
movsd 0x80(%rax), %xmm0
ucomisd -0x88(%rbp), %xmm0
jne 0x2f04c
jp 0x2f04c
jmp 0x2ef79
leaq 0x4bc00(%rip), %rdi     # 0x7ab80
callq 0x10380
movq -0x98(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x57fc3(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x57fb2(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x57fa4(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x4bb05(%rip), %rsi     # 0x7aad6
movl $0x50, %edx
callq 0x10840
movq 0x57f7e(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x57f70(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x57f58(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x57f48(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x57f3b(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x57f2d(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x1c(%rbp)
jmp 0x2f0c4
jmp 0x2f04e
callq 0x11260
movq -0x30(%rbp), %rax
movl 0x1d0(%rax), %edi
movsd -0x48(%rbp), %xmm0
movsd -0x50(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movsd -0x60(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x70(%rbp), %xmm5
movsd -0x78(%rbp), %xmm6
movsd -0x80(%rbp), %xmm7
movsd -0x88(%rbp), %xmm8
movsd %xmm8, (%rsp)
movzbl -0x89(%rbp), %esi
callq 0x10470
callq 0x10050
movl -0x34(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x1798(%rax)
movq -0x40(%rbp), %rax
movb $0x1, 0xc680(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)