// File: /workspace/github_cpp_makefile_star2_O2/sundale[P]gcode/rs274ngc/interp_convert.cc
// Function: Interp::convert_home(int, block_struct*, setup_struct*)
int Interp::convert_home(int move,       //!< G code, must be G_28 or G_30            
                        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;
  double v_end;
  double w_end;
  double end_x_home;
  double end_y_home;
  double end_z_home;
  double AA_end_home;
  double BB_end_home;
  double CC_end_home;
  double u_end_home;
  double v_end_home;
  double w_end_home;
  double *parameters;

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

  CHKS((settings->cutter_comp_side != OFF),
      NCE_CANNOT_USE_G28_OR_G30_WITH_CUTTER_RADIUS_COMP);

  // waypoint is in currently active coordinate system

  STRAIGHT_TRAVERSE(block->line_number, end_x, end_y, end_z,
                    AA_end, BB_end, CC_end,
                    u_end, v_end, w_end);

  if (move == G_28) {
      find_relative(USER_TO_PROGRAM_LEN(parameters[5161]),
                    USER_TO_PROGRAM_LEN(parameters[5162]),
                    USER_TO_PROGRAM_LEN(parameters[5163]),
                    USER_TO_PROGRAM_ANG(parameters[5164]),
                    USER_TO_PROGRAM_ANG(parameters[5165]),
                    USER_TO_PROGRAM_ANG(parameters[5166]),
                    USER_TO_PROGRAM_LEN(parameters[5167]),
                    USER_TO_PROGRAM_LEN(parameters[5168]),
                    USER_TO_PROGRAM_LEN(parameters[5169]),
                    &end_x_home, &end_y_home, &end_z_home,
                    &AA_end_home, &BB_end_home, &CC_end_home, 
                    &u_end_home, &v_end_home, &w_end_home, settings);
  } else if (move == G_30) {
      find_relative(USER_TO_PROGRAM_LEN(parameters[5181]),
                    USER_TO_PROGRAM_LEN(parameters[5182]),
                    USER_TO_PROGRAM_LEN(parameters[5183]),
                    USER_TO_PROGRAM_ANG(parameters[5184]),
                    USER_TO_PROGRAM_ANG(parameters[5185]),
                    USER_TO_PROGRAM_ANG(parameters[5186]),
                    USER_TO_PROGRAM_LEN(parameters[5187]),
                    USER_TO_PROGRAM_LEN(parameters[5188]),
                    USER_TO_PROGRAM_LEN(parameters[5189]),
                    &end_x_home, &end_y_home, &end_z_home,
                    &AA_end_home, &BB_end_home, &CC_end_home, 
                    &u_end_home, &v_end_home, &w_end_home, settings);
  } else
    ERS(NCE_BUG_CODE_NOT_G28_OR_G30);
  
  // if any axes are specified, home only those axes after the waypoint 
  // (both fanuc & haas, contrary to emc historical operation)

  if (block->x_flag == ON) end_x = end_x_home;  
  if (block->y_flag == ON) end_y = end_y_home;  
  if (block->z_flag == ON) end_z = end_z_home;  
  if (block->a_flag == ON) AA_end = AA_end_home;
  if (block->b_flag == ON) BB_end = BB_end_home;
  if (block->c_flag == ON) CC_end = CC_end_home;
  if (block->u_flag == ON) u_end = u_end_home;  
  if (block->v_flag == ON) v_end = v_end_home;  
  if (block->w_flag == ON) w_end = w_end_home;  

  // but, if no axes are specified, home all of them 
  // (haas does this, emc historical did, throws an error in fanuc)

  if (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) {
      end_x = end_x_home;  
      end_y = end_y_home;  
      end_z = end_z_home;  
      AA_end = AA_end_home;
      BB_end = BB_end_home;
      CC_end = CC_end_home;
      u_end = u_end_home;  
      v_end = v_end_home;  
      w_end = w_end_home;  
  }

  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;
  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 $0x178, %rsp            # imm = 0x178
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r15
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 -0x88(%rbp), %rcx
leaq -0x80(%rbp), %r8
leaq -0x78(%rbp), %r9
movq %rdx, %rsi
movq %rbx, %rdx
callq 0xbb30
testl %eax, %eax
je 0x13ac6
movl %eax, %r13d
movq 0x294f1(%rip), %rbx     # 0x3cf60
movslq 0xd670(%rbx), %rax
cmpq $0x30, %rax
jg 0x14201
imulq $0x50, %rax, %rax
leaq (%rbx,%rax), %rdi
addq $0xc6d0, %rdi           # imm = 0xC6D0
leaq 0x1cda0(%rip), %rsi     # 0x30836
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 0x14201
cmpl $0x0, 0x624(%rbx)
je 0x13b20
leaq 0x1df71(%rip), %rdi     # 0x31a47
callq 0xb220
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0xb8e0
movq 0x29471(%rip), %rbx     # 0x3cf60
leaq 0xc6d0(%rbx), %rdi
leaq 0x1cd39(%rip), %rsi     # 0x30836
pushq $0x50
popq %rdx
callq 0xb940
andw $0x0, 0xc71f(%rbx)
movl $0x1, 0xd670(%rbx)
pushq $0x5
popq %r13
jmp 0x14201
movl 0x1d0(%r14), %edi
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0x78(%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
cmpl $0x118, %r12d           # imm = 0x118
je 0x13bd1
cmpl $0x12c, %r12d           # imm = 0x12C
jne 0x140fd
movl $0xb9e8, %eax           # imm = 0xB9E8
movq %rax, -0xa8(%rbp)
movl $0xb9e0, %eax           # imm = 0xB9E0
movq %rax, -0x30(%rbp)
movl $0xb9d8, %eax           # imm = 0xB9D8
movq %rax, -0x38(%rbp)
movl $0xb9d0, %eax           # imm = 0xB9D0
movq %rax, -0x90(%rbp)
movl $0xb9c8, %eax           # imm = 0xB9C8
movq %rax, -0x98(%rbp)
movl $0xb9c0, %eax           # imm = 0xB9C0
movq %rax, -0xa0(%rbp)
movl $0xb9b8, %eax           # imm = 0xB9B8
movq %rax, -0x40(%rbp)
movl $0xb9b0, %r13d          # imm = 0xB9B0
movl $0xb9a8, %eax           # imm = 0xB9A8
jmp 0x13c27
movl $0xb948, %eax           # imm = 0xB948
movq %rax, -0xa8(%rbp)
movl $0xb940, %eax           # imm = 0xB940
movq %rax, -0x30(%rbp)
movl $0xb938, %eax           # imm = 0xB938
movq %rax, -0x38(%rbp)
movl $0xb930, %eax           # imm = 0xB930
movq %rax, -0x90(%rbp)
movl $0xb928, %eax           # imm = 0xB928
movq %rax, -0x98(%rbp)
movl $0xb920, %eax           # imm = 0xB920
movq %rax, -0xa0(%rbp)
movl $0xb918, %eax           # imm = 0xB918
movq %rax, -0x40(%rbp)
movl $0xb910, %r13d          # imm = 0xB910
movl $0xb908, %eax           # imm = 0xB908
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xb8(%rbp)
callq 0xba40
movsd %xmm0, -0x168(%rbp)
movq 0x29318(%rip), %r12     # 0x3cf60
movl 0x1690(%r12), %eax
movsd 0x1c268(%rip), %xmm0    # 0x2fec0
movsd %xmm0, -0xc0(%rbp)
cmpl $0x3, %eax
je 0x13c6d
movsd 0x1c233(%rip), %xmm0    # 0x2fea0
movsd 0x1c253(%rip), %xmm1    # 0x2fec8
movsd %xmm1, -0xc8(%rbp)
cmpl $0x1, %eax
je 0x13c85
movaps %xmm0, %xmm1
movsd %xmm1, -0x170(%rbp)
movsd (%rbx,%r13), %xmm0
movsd %xmm0, -0xb0(%rbp)
callq 0xba40
movsd %xmm0, -0x158(%rbp)
movl 0x1690(%r12), %eax
movsd 0x1c208(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x13cc5
movsd 0x1c1db(%rip), %xmm0    # 0x2fea0
movsd 0x1c1fb(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x13cd5
movaps %xmm0, %xmm1
movsd %xmm1, -0x160(%rbp)
movq -0x40(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
callq 0xba40
movsd %xmm0, -0x140(%rbp)
movl 0x1690(%r12), %eax
movsd 0x1c1b8(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x13d15
movsd 0x1c18b(%rip), %xmm0    # 0x2fea0
movsd 0x1c1ab(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x13d25
movaps %xmm0, %xmm1
movsd %xmm1, -0x150(%rbp)
movq -0xa0(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xa0(%rbp)
callq 0xc090
movsd %xmm0, -0x148(%rbp)
movq -0x98(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x98(%rbp)
callq 0xc090
movsd %xmm0, -0x138(%rbp)
movq -0x90(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
callq 0xc090
movsd %xmm0, -0x130(%rbp)
movq -0x38(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0xba40
movsd %xmm0, -0x120(%rbp)
movl 0x1690(%r12), %eax
movsd 0x1c105(%rip), %xmm0    # 0x2fec0
cmpl $0x3, %eax
je 0x13dc8
movsd 0x1c0d8(%rip), %xmm0    # 0x2fea0
movsd 0x1c0f8(%rip), %xmm1    # 0x2fec8
cmpl $0x1, %eax
je 0x13dd8
movaps %xmm0, %xmm1
movsd %xmm1, -0x128(%rbp)
movq -0x30(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0xba40
movl 0x1690(%r12), %eax
movsd 0x1c0bd(%rip), %xmm1    # 0x2fec0
cmpl $0x3, %eax
je 0x13e10
movsd 0x1c090(%rip), %xmm1    # 0x2fea0
movsd 0x1c0b0(%rip), %xmm5    # 0x2fec8
cmpl $0x1, %eax
movsd -0xb0(%rbp), %xmm2
movsd -0x40(%rbp), %xmm3
movsd -0x38(%rbp), %xmm4
je 0x13e32
movaps %xmm1, %xmm5
movsd %xmm5, -0x118(%rbp)
movsd -0xb8(%rbp), %xmm1
divsd -0x168(%rbp), %xmm1
movsd %xmm1, -0xb8(%rbp)
divsd -0x158(%rbp), %xmm2
movsd %xmm2, -0xb0(%rbp)
divsd -0x140(%rbp), %xmm3
movsd %xmm3, -0x40(%rbp)
divsd -0x120(%rbp), %xmm4
movsd %xmm4, -0x38(%rbp)
movsd -0x30(%rbp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movq -0xa8(%rbp), %rax
movsd (%rbx,%rax), %xmm0
movsd %xmm0, -0xa8(%rbp)
callq 0xba40
movl 0x1690(%r12), %eax
cmpl $0x3, %eax
je 0x13ec0
movsd 0x1bfe8(%rip), %xmm1    # 0x2fea0
movsd %xmm1, -0xc0(%rbp)
movsd -0xb8(%rbp), %xmm8
divsd -0x170(%rbp), %xmm8
movsd -0xb0(%rbp), %xmm1
divsd -0x160(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
divsd -0x150(%rbp), %xmm2
movsd -0xa0(%rbp), %xmm3
divsd -0x148(%rbp), %xmm3
movsd -0x98(%rbp), %xmm4
divsd -0x138(%rbp), %xmm4
movsd -0x90(%rbp), %xmm5
divsd -0x130(%rbp), %xmm5
movsd -0x38(%rbp), %xmm6
divsd -0x128(%rbp), %xmm6
movsd -0x30(%rbp), %xmm7
divsd -0x118(%rbp), %xmm7
movsd -0xa8(%rbp), %xmm9
divsd %xmm0, %xmm9
cmpl $0x1, %eax
je 0x13f5c
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
divsd -0xc8(%rbp), %xmm9
movq %rbx, 0x28(%rsp)
leaq -0xd0(%rbp), %rax
movq %rax, 0x20(%rsp)
leaq -0xd8(%rbp), %rax
movq %rax, 0x18(%rsp)
leaq -0xe0(%rbp), %rax
movq %rax, 0x10(%rsp)
leaq -0xe8(%rbp), %rax
movq %rax, 0x8(%rsp)
movsd %xmm9, (%rsp)
leaq -0x110(%rbp), %rsi
leaq -0x108(%rbp), %rdx
leaq -0x100(%rbp), %rcx
leaq -0xf8(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq %r15, %rdi
movapd %xmm8, %xmm0
callq 0xb440
movb 0x270(%r14), %al
cmpb $0x1, %al
jne 0x13feb
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movb 0x280(%r14), %cl
cmpb $0x1, %cl
jne 0x14004
movsd -0x108(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movb 0x290(%r14), %dl
cmpb $0x1, %dl
jne 0x1401d
movsd -0x100(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movb (%r14), %dil
cmpb $0x1, %dil
jne 0x14033
movsd -0xf8(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movb 0x10(%r14), %sil
cmpb $0x1, %sil
jne 0x1404a
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movb 0x20(%r14), %r8b
cmpb $0x1, %r8b
jne 0x14061
movsd -0xe8(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movb 0x244(%r14), %r9b
cmpb $0x1, %r9b
jne 0x1407b
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movb 0x250(%r14), %r10b
cmpb $0x1, %r10b
jne 0x14095
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movb 0x260(%r14), %r11b
cmpb $0x1, %r11b
jne 0x140af
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
orb %al, %cl
orb %dil, %dl
orb %cl, %dl
orb %r8b, %sil
orb %r9b, %sil
orb %dl, %sil
orb %r10b, %sil
orb %r11b, %sil
je 0x14109
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0x78(%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
jmp 0x14183
leaq 0x1d971(%rip), %rdi     # 0x31a75
jmp 0x13ad6
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x108(%rbp), %xmm1
movsd %xmm1, -0x80(%rbp)
movsd -0x100(%rbp), %xmm2
movsd %xmm2, -0x78(%rbp)
movsd -0xf8(%rbp), %xmm3
movsd %xmm3, -0x70(%rbp)
movsd -0xf0(%rbp), %xmm4
movsd %xmm4, -0x68(%rbp)
movsd -0xe8(%rbp), %xmm5
movsd %xmm5, -0x60(%rbp)
movsd -0xe0(%rbp), %xmm6
movsd %xmm6, -0x58(%rbp)
movsd -0xd8(%rbp), %xmm7
movsd %xmm7, -0x50(%rbp)
movsd -0xd0(%rbp), %xmm8
movsd %xmm8, -0x48(%rbp)
movl 0x1d0(%r14), %edi
movsd %xmm8, (%rsp)
callq 0xb970
movsd -0x88(%rbp), %xmm0
movsd %xmm0, 0x600(%rbx)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, 0x608(%rbx)
movsd -0x78(%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
movl %r13d, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq