// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_straight(int, block_struct*, setup_struct*)
int Interp::convert_straight(int move,   //!< either G_0 or G_1                       
                            block_pointer block,        //!< pointer to a block of RS274 instructions
                            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, v_end, w_end;
  int status;

  settings->arc_not_allowed = OFF;

  if (move == G_1) {
    if (settings->feed_mode == UNITS_PER_MINUTE) {
      CHKS((settings->feed_rate == 0.0), NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE);
    } else if (settings->feed_mode == UNITS_PER_REVOLUTION) {
      CHKS((settings->feed_rate == 0.0), NCE_CANNOT_DO_G1_WITH_ZERO_FEED_RATE);
      CHKS((settings->speed == 0.0), "Cannot feed with zero spindle speed in feed per rev mode");
    } else if (settings->feed_mode == INVERSE_TIME) {
      CHKS((block->f_number == -1.0),
          NCE_F_WORD_MISSING_WITH_INVERSE_TIME_G1_MOVE);
    }
  }

  settings->motion_mode = move;
  CHP(find_ends(block, settings, &end_x, &end_y, &end_z,
                &AA_end, &BB_end, &CC_end, &u_end, &v_end, &w_end));

  if (move == G_1) {
      inverse_time_rate_straight(end_x, end_y, end_z,
                                 AA_end, BB_end, CC_end,
                                 u_end, v_end, w_end,
                                 block, settings);
  }

  if ((settings->cutter_comp_side != OFF) &&    /* ! "== ON" */
      (settings->cutter_comp_radius > 0.0)) {   /* radius always is >= 0 */

    CHKS((block->g_modes[0] == G_53),
        NCE_CANNOT_USE_G53_WITH_CUTTER_RADIUS_COMP);

    if(settings->plane == CANON_PLANE_XZ) {
        if (settings->cutter_comp_firstmove == ON)
            status = convert_straight_comp1(move, block, settings, end_z, end_x, end_y,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
        else
            status = convert_straight_comp2(move, block, settings, end_z, end_x, end_y,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
    } else if(settings->plane == CANON_PLANE_XY) {
        if (settings->cutter_comp_firstmove == ON)
            status = convert_straight_comp1(move, block, settings, end_x, end_y, end_z,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
        else
            status = convert_straight_comp2(move, block, settings, end_x, end_y, end_z,
                                            AA_end, BB_end, CC_end, u_end, v_end, w_end);
    } else ERS("BUG: Invalid plane for cutter compensation");
    CHP(status);
  } else if (move == G_0) {
    STRAIGHT_TRAVERSE(block->line_number, end_x, end_y, end_z,
                      AA_end, BB_end, CC_end,
                      u_end, v_end, w_end);
    settings->current_x = end_x;
    settings->current_y = end_y;
    settings->current_z = end_z;
  } else if (move == G_1) {
    STRAIGHT_FEED(block->line_number, end_x, end_y, end_z,
                  AA_end, BB_end, CC_end,
                  u_end, v_end, w_end);
    settings->current_x = end_x;
    settings->current_y = end_y;
    settings->current_z = end_z;
  } else if (move == G_33) {
    CHKS(((settings->spindle_turning != CANON_CLOCKWISE) &&
           (settings->spindle_turning != CANON_COUNTERCLOCKWISE)),
          "Spindle not turning in G33");
    START_SPEED_FEED_SYNCH(block->k_number, 0);
    STRAIGHT_FEED(block->line_number, end_x, end_y, end_z, AA_end, BB_end, CC_end, u_end, v_end, w_end);
    STOP_SPEED_FEED_SYNCH();
    settings->current_x = end_x;
    settings->current_y = end_y;
    settings->current_z = end_z;
  } else if (move == G_33_1) {
    CHKS(((settings->spindle_turning != CANON_CLOCKWISE) &&
           (settings->spindle_turning != CANON_COUNTERCLOCKWISE)),
          "Spindle not turning in G33.1");
    START_SPEED_FEED_SYNCH(block->k_number, 0);
    RIGID_TAP(block->line_number, end_x, end_y, end_z);
    STOP_SPEED_FEED_SYNCH();
    // after the RIGID_TAP cycle we'll be in the same spot
  } else if (move == G_76) {
    CHKS((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_CANNOT_MOVE_ROTARY_AXES_WITH_G76);
    int result = convert_threading_cycle(block, settings, end_x, end_y, end_z);
    if(result != INTERP_OK) return result;
  } else
    ERS(NCE_BUG_CODE_NOT_G0_OR_G1);

  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;
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, %rbx
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %r14
movb $0x0, 0x110(%rcx)
cmpl $0xa, %esi
jne 0x168fe
movl 0x670(%rbx), %eax
cmpl $0x2, %eax
je 0x168c2
cmpl $0x1, %eax
je 0x168a1
testl %eax, %eax
jne 0x168fe
movsd 0x678(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x168fe
jnp 0x168d6
jmp 0x168fe
movsd 0x148(%r15), %xmm0
ucomisd 0x18fbe(%rip), %xmm0    # 0x2f870
jne 0x168fe
jp 0x168fe
leaq 0x1b9f4(%rip), %rdi     # 0x322b1
jmp 0x16ca9
movsd 0x678(%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x168e2
jp 0x168e2
leaq 0x1b9b3(%rip), %rdi     # 0x32290
jmp 0x16ca9
movsd 0xc6b8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x168fe
jp 0x168fe
leaq 0x1a5f7(%rip), %rsi     # 0x30ef0
jmp 0x16d90
movl %r12d, 0x1798(%rbx)
leaq -0x48(%rbp), %rax
movq %rax, 0x28(%rsp)
leaq -0x50(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0x58(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0x60(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0x68(%rbp), %rax
movq %rax, 0x8(%rsp)
leaq -0x70(%rbp), %rax
movq %rax, (%rsp)
leaq -0x40(%rbp), %rcx
leaq -0x38(%rbp), %r8
leaq -0x30(%rbp), %r9
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xbb30
testl %eax, %eax
je 0x169b9
movl %eax, %r13d
movq 0x265fe(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x16cee
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1a042(%rip), %rsi     # 0x309cb
pushq $0x50
popq %rdx
callq 0xb940
movslq 0xd670(%rbx), %rax
imulq $0x50, %rax, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x16cee
cmpl $0xa, %r12d
jne 0x16a01
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xb900
cmpl $0x0, 0x624(%rbx)
je 0x16a39
movsd 0x618(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16a39
cmpl $0x212, 0x150(%r15) # imm = 0x212
jne 0x16bcb
leaq 0x1b8a6(%rip), %rdi     # 0x322da
jmp 0x16ca9
testl %r12d, %r12d
je 0x16a8a
cmpl $0xa, %r12d
jne 0x16b38
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
callq 0xb720
jmp 0x16aca
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
callq 0xb970
movsd -0x40(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x610(%rbx)
movsd -0x70(%rbp), %xmm0
movsd %xmm0, 0x8(%rbx)
movsd -0x68(%rbp), %xmm0
movsd %xmm0, 0x20(%rbx)
movsd -0x60(%rbp), %xmm0
movsd %xmm0, 0x38(%rbx)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x50(%rbx)
movsd -0x50(%rbp), %xmm0
movsd %xmm0, 0x68(%rbx)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x80(%rbx)
xorl %r13d, %r13d
jmp 0x16cee
cmpl $0x2f8, %r12d           # imm = 0x2F8
je 0x16c3e
cmpl $0x14b, %r12d           # imm = 0x14B
je 0x16bf7
cmpl $0x14a, %r12d           # imm = 0x14A
jne 0x16ca2
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x16d89
movsd 0x1c0(%r15), %xmm0
xorl %edi, %edi
callq 0xc020
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
movsd %xmm8, (%rsp)
callq 0xb720
callq 0xb630
jmp 0x16aca
movl 0xc67c(%rbx), %eax
cmpl $0x1, %eax
je 0x16d00
cmpl $0x3, %eax
jne 0x16d77
movsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
jmp 0x16d0f
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x16d80
movsd 0x1c0(%r15), %xmm0
xorl %edi, %edi
callq 0xc020
movl 0x1d0(%r15), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
callq 0xbbc0
callq 0xb630
jmp 0x16af1
movsd 0x8(%rbx), %xmm0
ucomisd -0x70(%rbp), %xmm0
jne 0x16c99
jp 0x16c99
movsd 0x20(%rbx), %xmm0
ucomisd -0x68(%rbp), %xmm0
jne 0x16c99
jp 0x16c99
movsd 0x38(%rbx), %xmm0
ucomisd -0x60(%rbp), %xmm0
jne 0x16c99
jp 0x16c99
movsd 0x50(%rbx), %xmm0
ucomisd -0x58(%rbp), %xmm0
jne 0x16c99
jp 0x16c99
movsd 0x68(%rbx), %xmm0
ucomisd -0x50(%rbp), %xmm0
jne 0x16c99
jp 0x16c99
movsd 0x80(%rbx), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x16c99
jnp 0x16d98
leaq 0x1b6c4(%rip), %rdi     # 0x32364
jmp 0x16ca9
leaq 0x1b6dc(%rip), %rdi     # 0x32385
callq 0xb220
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x2629e(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x19cfb(%rip), %rsi     # 0x309cb
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r13
movl %r13d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movsd -0x70(%rbp), %xmm3
movsd -0x68(%rbp), %xmm4
movsd -0x60(%rbp), %xmm5
movsd -0x58(%rbp), %xmm6
movsd -0x50(%rbp), %xmm7
movsd -0x48(%rbp), %xmm8
cmpb $0x1, 0xc689(%rbx)
jne 0x16d50
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xb830
jmp 0x16d67
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r12d, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xb5f0
movl %eax, %r13d
testl %eax, %eax
jne 0x1695b
jmp 0x16af1
leaq 0x1b583(%rip), %rsi     # 0x32301
jmp 0x16d90
leaq 0x1b5c0(%rip), %rsi     # 0x32347
jmp 0x16d90
leaq 0x1b59c(%rip), %rsi     # 0x3232c
movq %r14, %rdi
jmp 0x16cb4
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xc350
movl %eax, %r13d
testl %eax, %eax
jne 0x16cee
jmp 0x16af1
nop