// File: sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_length_units(int, setup_struct*)
int Interp::convert_length_units(int g_code,     //!< g_code being executed (must be G_20 or G_21)
                                setup_pointer settings) //!< pointer to machine settings                 
{
  if (g_code == G_20) {
    USE_LENGTH_UNITS(CANON_UNITS_INCHES);
    if (settings->length_units != CANON_UNITS_INCHES) {
      settings->length_units = CANON_UNITS_INCHES;
      settings->current_x = (settings->current_x * INCH_PER_MM);
      settings->current_y = (settings->current_y * INCH_PER_MM);
      settings->current_z = (settings->current_z * INCH_PER_MM);
      settings->program_x = (settings->program_x * INCH_PER_MM);
      settings->program_y = (settings->program_y * INCH_PER_MM);
      settings->program_z = (settings->program_z * INCH_PER_MM);
      qc_scale(INCH_PER_MM);
      settings->cutter_comp_radius *= INCH_PER_MM;
      settings->axis_offset_x = (settings->axis_offset_x * INCH_PER_MM);
      settings->axis_offset_y = (settings->axis_offset_y * INCH_PER_MM);
      settings->axis_offset_z = (settings->axis_offset_z * INCH_PER_MM);
      settings->origin_offset_x = (settings->origin_offset_x * INCH_PER_MM);
      settings->origin_offset_y = (settings->origin_offset_y * INCH_PER_MM);
      settings->origin_offset_z = (settings->origin_offset_z * INCH_PER_MM);

      settings->u_current = (settings->u_current * INCH_PER_MM);
      settings->v_current = (settings->v_current * INCH_PER_MM);
      settings->w_current = (settings->w_current * INCH_PER_MM);
      settings->u_axis_offset = (settings->u_axis_offset * INCH_PER_MM);
      settings->v_axis_offset = (settings->v_axis_offset * INCH_PER_MM);
      settings->w_axis_offset = (settings->w_axis_offset * INCH_PER_MM);
      settings->u_origin_offset = (settings->u_origin_offset * INCH_PER_MM);
      settings->v_origin_offset = (settings->v_origin_offset * INCH_PER_MM);
      settings->w_origin_offset = (settings->w_origin_offset * INCH_PER_MM);

      settings->tool_offset.tran.x = GET_EXTERNAL_TOOL_LENGTH_XOFFSET();
      settings->tool_offset.tran.y = GET_EXTERNAL_TOOL_LENGTH_YOFFSET();
      settings->tool_offset.tran.z = GET_EXTERNAL_TOOL_LENGTH_ZOFFSET();
      settings->tool_offset.a = GET_EXTERNAL_TOOL_LENGTH_AOFFSET();
      settings->tool_offset.b = GET_EXTERNAL_TOOL_LENGTH_BOFFSET();
      settings->tool_offset.c = GET_EXTERNAL_TOOL_LENGTH_COFFSET();
      settings->tool_offset.u = GET_EXTERNAL_TOOL_LENGTH_UOFFSET();
      settings->tool_offset.v = GET_EXTERNAL_TOOL_LENGTH_VOFFSET();
      settings->tool_offset.w = GET_EXTERNAL_TOOL_LENGTH_WOFFSET();
      settings->feed_rate = GET_EXTERNAL_FEED_RATE();
    }
  } else if (g_code == G_21) {
    USE_LENGTH_UNITS(CANON_UNITS_MM);
    if (settings->length_units != CANON_UNITS_MM) {
      settings->length_units = CANON_UNITS_MM;
      settings->current_x = (settings->current_x * MM_PER_INCH);
      settings->current_y = (settings->current_y * MM_PER_INCH);
      settings->current_z = (settings->current_z * MM_PER_INCH);
      settings->program_x = (settings->program_x * MM_PER_INCH);
      settings->program_y = (settings->program_y * MM_PER_INCH);
      settings->program_z = (settings->program_z * MM_PER_INCH);
      qc_scale(MM_PER_INCH);
      settings->cutter_comp_radius *= MM_PER_INCH;
      settings->axis_offset_x = (settings->axis_offset_x * MM_PER_INCH);
      settings->axis_offset_y = (settings->axis_offset_y * MM_PER_INCH);
      settings->axis_offset_z = (settings->axis_offset_z * MM_PER_INCH);
      settings->origin_offset_x = (settings->origin_offset_x * MM_PER_INCH);
      settings->origin_offset_y = (settings->origin_offset_y * MM_PER_INCH);
      settings->origin_offset_z = (settings->origin_offset_z * MM_PER_INCH);

      settings->u_current = (settings->u_current * MM_PER_INCH);
      settings->v_current = (settings->v_current * MM_PER_INCH);
      settings->w_current = (settings->w_current * MM_PER_INCH);
      settings->u_axis_offset = (settings->u_axis_offset * MM_PER_INCH);
      settings->v_axis_offset = (settings->v_axis_offset * MM_PER_INCH);
      settings->w_axis_offset = (settings->w_axis_offset * MM_PER_INCH);
      settings->u_origin_offset = (settings->u_origin_offset * MM_PER_INCH);
      settings->v_origin_offset = (settings->v_origin_offset * MM_PER_INCH);
      settings->w_origin_offset = (settings->w_origin_offset * MM_PER_INCH);

      settings->tool_offset.tran.x = GET_EXTERNAL_TOOL_LENGTH_XOFFSET();
      settings->tool_offset.tran.y = GET_EXTERNAL_TOOL_LENGTH_YOFFSET();
      settings->tool_offset.tran.z = GET_EXTERNAL_TOOL_LENGTH_ZOFFSET();
      settings->tool_offset.a = GET_EXTERNAL_TOOL_LENGTH_AOFFSET();
      settings->tool_offset.b = GET_EXTERNAL_TOOL_LENGTH_BOFFSET();
      settings->tool_offset.c = GET_EXTERNAL_TOOL_LENGTH_COFFSET();
      settings->tool_offset.u = GET_EXTERNAL_TOOL_LENGTH_UOFFSET();
      settings->tool_offset.v = GET_EXTERNAL_TOOL_LENGTH_VOFFSET();
      settings->tool_offset.w = GET_EXTERNAL_TOOL_LENGTH_WOFFSET();
      settings->feed_rate = GET_EXTERNAL_FEED_RATE();
    }
  } else
    ERS(NCE_BUG_CODE_NOT_G20_OR_G21);
  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpl $0xc8, -0x14(%rbp)
jne 0x22edf
movl $0x1, %edi
callq 0x10e20
movq -0x20(%rbp), %rax
cmpl $0x1, 0x1690(%rax)
je 0x22eda
movq -0x20(%rbp), %rax
movl $0x1, 0x1690(%rax)
movq -0x20(%rbp), %rax
movsd 0x562cb(%rip), %xmm0    # 0x78e68
mulsd 0x600(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x600(%rax)
movq -0x20(%rbp), %rax
movsd 0x562ab(%rip), %xmm0    # 0x78e68
mulsd 0x608(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x608(%rax)
movq -0x20(%rbp), %rax
movsd 0x5628b(%rip), %xmm0    # 0x78e68
mulsd 0x610(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x610(%rax)
movq -0x20(%rbp), %rax
movsd 0x5626b(%rip), %xmm0    # 0x78e68
mulsd 0xc690(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc690(%rax)
movq -0x20(%rbp), %rax
movsd 0x5624b(%rip), %xmm0    # 0x78e68
mulsd 0xc698(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc698(%rax)
movq -0x20(%rbp), %rax
movsd 0x5622b(%rip), %xmm0    # 0x78e68
mulsd 0xc6a0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc6a0(%rax)
movsd 0x5620f(%rip), %xmm0    # 0x78e68
callq 0x11ab0
movq -0x20(%rbp), %rax
movsd 0x561fe(%rip), %xmm0    # 0x78e68
mulsd 0x618(%rax), %xmm0
movsd %xmm0, 0x618(%rax)
movq -0x20(%rbp), %rax
movsd 0x561e2(%rip), %xmm0    # 0x78e68
mulsd 0x118(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x118(%rax)
movq -0x20(%rbp), %rax
movsd 0x561c2(%rip), %xmm0    # 0x78e68
mulsd 0x120(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x120(%rax)
movq -0x20(%rbp), %rax
movsd 0x561a2(%rip), %xmm0    # 0x78e68
mulsd 0x128(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x128(%rax)
movq -0x20(%rbp), %rax
movsd 0x56182(%rip), %xmm0    # 0x78e68
mulsd 0x17a0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17a0(%rax)
movq -0x20(%rbp), %rax
movsd 0x56162(%rip), %xmm0    # 0x78e68
mulsd 0x17a8(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17a8(%rax)
movq -0x20(%rbp), %rax
movsd 0x56142(%rip), %xmm0    # 0x78e68
mulsd 0x17b0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17b0(%rax)
movq -0x20(%rbp), %rax
movsd 0x56122(%rip), %xmm0    # 0x78e68
mulsd 0x50(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x50(%rax)
movq -0x20(%rbp), %rax
movsd 0x56108(%rip), %xmm0    # 0x78e68
mulsd 0x68(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movq -0x20(%rbp), %rax
movsd 0x560ee(%rip), %xmm0    # 0x78e68
mulsd 0x80(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x20(%rbp), %rax
movsd 0x560ce(%rip), %xmm0    # 0x78e68
mulsd 0x48(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x48(%rax)
movq -0x20(%rbp), %rax
movsd 0x560b4(%rip), %xmm0    # 0x78e68
mulsd 0x60(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x60(%rax)
movq -0x20(%rbp), %rax
movsd 0x5609a(%rip), %xmm0    # 0x78e68
mulsd 0x78(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x78(%rax)
movq -0x20(%rbp), %rax
movsd 0x56080(%rip), %xmm0    # 0x78e68
mulsd 0x58(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movq -0x20(%rbp), %rax
movsd 0x56066(%rip), %xmm0    # 0x78e68
mulsd 0x70(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x70(%rax)
movq -0x20(%rbp), %rax
movsd 0x5604c(%rip), %xmm0    # 0x78e68
mulsd 0x88(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x88(%rax)
callq 0x100b0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd678(%rax)
callq 0x11b10
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd680(%rax)
callq 0x11fe0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd688(%rax)
callq 0x11e10
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd690(%rax)
callq 0x100d0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd698(%rax)
callq 0x10bb0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6a0(%rax)
callq 0x10140
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6a8(%rax)
callq 0x10aa0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6b0(%rax)
callq 0x11cf0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6b8(%rax)
callq 0x11450
movq -0x20(%rbp), %rax
movsd %xmm0, 0x678(%rax)
jmp 0x23337
cmpl $0xd2, -0x14(%rbp)
jne 0x23263
movl $0x2, %edi
callq 0x10e20
movq -0x20(%rbp), %rax
cmpl $0x2, 0x1690(%rax)
je 0x2325e
movq -0x20(%rbp), %rax
movl $0x2, 0x1690(%rax)
movq -0x20(%rbp), %rax
movsd 0x55f27(%rip), %xmm0    # 0x78e48
mulsd 0x600(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x600(%rax)
movq -0x20(%rbp), %rax
movsd 0x55f07(%rip), %xmm0    # 0x78e48
mulsd 0x608(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x608(%rax)
movq -0x20(%rbp), %rax
movsd 0x55ee7(%rip), %xmm0    # 0x78e48
mulsd 0x610(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x610(%rax)
movq -0x20(%rbp), %rax
movsd 0x55ec7(%rip), %xmm0    # 0x78e48
mulsd 0xc690(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc690(%rax)
movq -0x20(%rbp), %rax
movsd 0x55ea7(%rip), %xmm0    # 0x78e48
mulsd 0xc698(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc698(%rax)
movq -0x20(%rbp), %rax
movsd 0x55e87(%rip), %xmm0    # 0x78e48
mulsd 0xc6a0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xc6a0(%rax)
movsd 0x55e6b(%rip), %xmm0    # 0x78e48
callq 0x11ab0
movq -0x20(%rbp), %rax
movsd 0x55e5a(%rip), %xmm0    # 0x78e48
mulsd 0x618(%rax), %xmm0
movsd %xmm0, 0x618(%rax)
movq -0x20(%rbp), %rax
movsd 0x55e3e(%rip), %xmm0    # 0x78e48
mulsd 0x118(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x118(%rax)
movq -0x20(%rbp), %rax
movsd 0x55e1e(%rip), %xmm0    # 0x78e48
mulsd 0x120(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x120(%rax)
movq -0x20(%rbp), %rax
movsd 0x55dfe(%rip), %xmm0    # 0x78e48
mulsd 0x128(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x128(%rax)
movq -0x20(%rbp), %rax
movsd 0x55dde(%rip), %xmm0    # 0x78e48
mulsd 0x17a0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17a0(%rax)
movq -0x20(%rbp), %rax
movsd 0x55dbe(%rip), %xmm0    # 0x78e48
mulsd 0x17a8(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17a8(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d9e(%rip), %xmm0    # 0x78e48
mulsd 0x17b0(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x17b0(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d7e(%rip), %xmm0    # 0x78e48
mulsd 0x50(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x50(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d64(%rip), %xmm0    # 0x78e48
mulsd 0x68(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x68(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d4a(%rip), %xmm0    # 0x78e48
mulsd 0x80(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x80(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d2a(%rip), %xmm0    # 0x78e48
mulsd 0x48(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x48(%rax)
movq -0x20(%rbp), %rax
movsd 0x55d10(%rip), %xmm0    # 0x78e48
mulsd 0x60(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x60(%rax)
movq -0x20(%rbp), %rax
movsd 0x55cf6(%rip), %xmm0    # 0x78e48
mulsd 0x78(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x78(%rax)
movq -0x20(%rbp), %rax
movsd 0x55cdc(%rip), %xmm0    # 0x78e48
mulsd 0x58(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x58(%rax)
movq -0x20(%rbp), %rax
movsd 0x55cc2(%rip), %xmm0    # 0x78e48
mulsd 0x70(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x70(%rax)
movq -0x20(%rbp), %rax
movsd 0x55ca8(%rip), %xmm0    # 0x78e48
mulsd 0x88(%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, 0x88(%rax)
callq 0x100b0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd678(%rax)
callq 0x11b10
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd680(%rax)
callq 0x11fe0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd688(%rax)
callq 0x11e10
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd690(%rax)
callq 0x100d0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd698(%rax)
callq 0x10bb0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6a0(%rax)
callq 0x10140
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6a8(%rax)
callq 0x10aa0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6b0(%rax)
callq 0x11cf0
movq -0x20(%rbp), %rax
movsd %xmm0, 0xd6b8(%rax)
callq 0x11450
movq -0x20(%rbp), %rax
movsd %xmm0, 0x678(%rax)
jmp 0x23335
jmp 0x23265
leaq 0x57250(%rip), %rdi     # 0x7a4bc
callq 0x10380
movq -0x28(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x63cda(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x63cc9(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x63cbb(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x5721a(%rip), %rsi     # 0x7a4d4
movl $0x50, %edx
callq 0x10840
movq 0x63c95(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x63c87(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x63c6f(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x63c5f(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x63c52(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x63c44(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x2333e
jmp 0x23337
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)