// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movl %esi, %r13d
movq %rdi, %r14
movb $0x0, 0x110(%rcx)
cmpl $0xa, %esi
jne 0x16cc3
movl 0x670(%rbx), %eax
cmpl $0x2, %eax
je 0x16c87
cmpl $0x1, %eax
je 0x16c65
testl %eax, %eax
jne 0x16cc3
movsd 0x678(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x16cc3
jnp 0x16c9b
jmp 0x16cc3
movsd 0x148(%r12), %xmm0
ucomisd 0x1fbf9(%rip), %xmm0    # 0x36870
jne 0x16cc3
jp 0x16cc3
leaq 0x22625(%rip), %rdi     # 0x392a7
jmp 0x1707f
movsd 0x678(%rbx), %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jne 0x16ca7
jp 0x16ca7
leaq 0x225e4(%rip), %rdi     # 0x39286
jmp 0x1707f
movsd 0xc6b8(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jne 0x16cc3
jp 0x16cc3
leaq 0x21232(%rip), %rsi     # 0x37ef0
jmp 0x171e5
movl %r13d, 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 %r12, %rsi
movq %rbx, %rdx
callq 0xaa70
movl %eax, %r15d
testl %eax, %eax
je 0x16d88
movq 0x2d239(%rip), %rbx     # 0x43f60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x170d3
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x20c79(%rip), %rsi     # 0x379cb
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%rbx), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%rbx,%rcx)
incl %eax
movl %eax, 0xd670(%rbx)
movb %dl, 0xc720(%rbx,%rcx)
jmp 0x170d3
cmpl $0xa, %r13d
jne 0x16dd0
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 %r12, %rsi
movq %rbx, %rdx
callq 0xa870
cmpl $0x0, 0x624(%rbx)
je 0x16e09
movsd 0x618(%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16e09
cmpl $0x212, 0x150(%r12) # imm = 0x212
jne 0x16f9f
leaq 0x224cc(%rip), %rdi     # 0x392d0
jmp 0x1707f
testl %r13d, %r13d
je 0x16e5b
cmpl $0xa, %r13d
jne 0x16f0a
movl 0x1d0(%r12), %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 0xa6d0
jmp 0x16e9c
movl 0x1d0(%r12), %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 0xa8d0
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 %r15d, %r15d
jmp 0x170d3
cmpl $0x2f8, %r13d           # imm = 0x2F8
je 0x17014
cmpl $0x14b, %r13d           # imm = 0x14B
je 0x16fcb
cmpl $0x14a, %r13d           # imm = 0x14A
jne 0x17078
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x171de
movsd 0x1c0(%r12), %xmm0
xorl %edi, %edi
callq 0xaef0
movl 0x1d0(%r12), %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 0xa6d0
callq 0xa5f0
jmp 0x16e9c
movl 0xc67c(%rbx), %eax
cmpl $0x1, %eax
je 0x170e5
cmpl $0x3, %eax
jne 0x171cc
movsd -0x30(%rbp), %xmm0
movsd -0x40(%rbp), %xmm1
movsd -0x38(%rbp), %xmm2
jmp 0x170f4
movl 0xc6cc(%rbx), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x171d5
movsd 0x1c0(%r12), %xmm0
xorl %edi, %edi
callq 0xaef0
movl 0x1d0(%r12), %edi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
callq 0xaaf0
callq 0xa5f0
jmp 0x16ec3
movsd 0x8(%rbx), %xmm0
ucomisd -0x70(%rbp), %xmm0
jne 0x1706f
jp 0x1706f
movsd 0x20(%rbx), %xmm0
ucomisd -0x68(%rbp), %xmm0
jne 0x1706f
jp 0x1706f
movsd 0x38(%rbx), %xmm0
ucomisd -0x60(%rbp), %xmm0
jne 0x1706f
jp 0x1706f
movsd 0x50(%rbx), %xmm0
ucomisd -0x58(%rbp), %xmm0
jne 0x1706f
jp 0x1706f
movsd 0x68(%rbx), %xmm0
ucomisd -0x50(%rbp), %xmm0
jne 0x1706f
jp 0x1706f
movsd 0x80(%rbx), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x1706f
jnp 0x171ed
leaq 0x222e4(%rip), %rdi     # 0x3935a
jmp 0x1707f
leaq 0x222fc(%rip), %rdi     # 0x3937b
callq 0xa1f0
movq %r14, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xa850
movq 0x2cec8(%rip), %rbx     # 0x43f60
movl $0x0, 0xd670(%rbx)
leaq 0xc6d0(%rbx), %rdi
leaq 0x2091b(%rip), %rsi     # 0x379cb
movl $0x50, %edx
callq 0xa8a0
movw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
movl $0x5, %r15d
movl %r15d, %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 0x17135
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xa7c0
jmp 0x1714c
movsd %xmm8, (%rsp)
movq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xa5b0
movl %eax, %r14d
testl %eax, %eax
je 0x171be
movq 0x2ce06(%rip), %r12     # 0x43f60
movslq 0xd670(%r12), %rax
movl %r14d, %r15d
cmpq $0x30, %rax
jg 0x171be
leaq (%rax,%rax,4), %rax
shlq $0x4, %rax
leaq (%r12,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x20846(%rip), %rsi     # 0x379cb
movl $0x50, %edx
callq 0xa8a0
movslq 0xd670(%r12), %rax
leaq (%rax,%rax,4), %rcx
shlq $0x4, %rcx
xorl %edx, %edx
movb %dl, 0xc71f(%r12,%rcx)
incl %eax
movl %eax, 0xd670(%r12)
movb %dl, 0xc720(%r12,%rcx)
movl %r14d, %r15d
testl %r14d, %r14d
jne 0x170d3
jmp 0x16ec3
leaq 0x22124(%rip), %rsi     # 0x392f7
jmp 0x171e5
leaq 0x22161(%rip), %rsi     # 0x3933d
jmp 0x171e5
leaq 0x2213d(%rip), %rsi     # 0x39322
movq %r14, %rdi
jmp 0x1708a
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
movsd -0x30(%rbp), %xmm2
movq %r14, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0xb1f0
testl %eax, %eax
cmovnel %eax, %r15d
jne 0x170d3
jmp 0x16ec3
nop