// File: mindbeast[P]rnes/cpu.cpp
// Function: void Rnes::Cpu::indexedIndirectFormat<&Rnes::Cpu::oraInst(unsigned short)>(Rnes::Cpu::Instruction const&)
void Cpu::indexedIndirectFormat(const Instruction &ins) {
  uint16_t immediateAddr = pc + 1;
  uint8_t immed = load(immediateAddr);
  uint8_t tableAddr = immed + x;
  uint16_t finalAddr = load(tableAddr);
  finalAddr |= (uint16_t)load((tableAddr + 1) & 0xff) << 8;

  std::stringstream str;
  str << std::setfill('0') << std::right;
  str << ins.nemonic << " ($" << std::hex << std::uppercase << std::setw(2) << (int)immed << ",X)";

  instTrace(str.str(), 2);

  pc += 2;
  (this->*fx)(finalAddr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
movl 0xc(%rdi), %eax
incl %eax
movw %ax, -0x12(%rbp)
movzwl -0x12(%rbp), %esi
callq 0x2dd90
movq -0x1f0(%rbp), %rdi
movb %al, -0x13(%rbp)
movzbl -0x13(%rbp), %eax
movzbl 0x9(%rdi), %ecx
addl %ecx, %eax
movb %al, -0x14(%rbp)
movzbl -0x14(%rbp), %esi
callq 0x2dd90
movq -0x1f0(%rbp), %rdi
movzbl %al, %eax
movw %ax, -0x16(%rbp)
movzbl -0x14(%rbp), %eax
incl %eax
movzbl %al, %esi
callq 0x2dd90
movzbl %al, %ecx
shll $0x8, %ecx
movzwl -0x16(%rbp), %eax
orl %ecx, %eax
movw %ax, -0x16(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0xe3f0
leaq -0x190(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movl $0x30, %edi
callq 0x39bf0
movb %al, -0x1d9(%rbp)
jmp 0x321d8
movq -0x1e8(%rbp), %rdi
movb -0x1d9(%rbp), %al
movb %al, -0x1a1(%rbp)
movzbl -0x1a1(%rbp), %esi
callq 0xe7b0
movq %rax, -0x1f8(%rbp)
jmp 0x32200
movq -0x1f8(%rbp), %rdi
leaq 0x7a02(%rip), %rsi      # 0x39c10
callq 0xed20
jmp 0x32215
leaq -0x190(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0xe3e0
movq %rax, -0x200(%rbp)
jmp 0x3222e
movq -0x200(%rbp), %rdi
leaq 0x37729(%rip), %rsi     # 0x69965
callq 0xe680
movq %rax, -0x208(%rbp)
jmp 0x3224a
movq -0x208(%rbp), %rdi
leaq 0x7a08(%rip), %rsi      # 0x39c60
callq 0xed20
movq %rax, -0x210(%rbp)
jmp 0x32266
movq -0x210(%rbp), %rdi
leaq 0x7a1c(%rip), %rsi      # 0x39c90
callq 0xed20
movq %rax, -0x218(%rbp)
jmp 0x32282
movl $0x2, %edi
callq 0x39c40
movq -0x218(%rbp), %rdi
movl %eax, -0x1b8(%rbp)
movl -0x1b8(%rbp), %esi
callq 0xe5f0
movq %rax, -0x220(%rbp)
jmp 0x322ad
movq -0x220(%rbp), %rdi
movzbl -0x13(%rbp), %esi
callq 0xe440
movq %rax, -0x228(%rbp)
jmp 0x322c6
movq -0x228(%rbp), %rdi
leaq 0x37695(%rip), %rsi     # 0x69969
callq 0xe680
jmp 0x322db
leaq -0x1d8(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0xe770
jmp 0x322f0
movq -0x1f0(%rbp), %rdi
leaq -0x1d8(%rbp), %rsi
movl $0x2, %edx
callq 0x30500
leaq -0x1d8(%rbp), %rdi
callq 0xed78
movq -0x1f0(%rbp), %rax
movzwl 0xc(%rax), %ecx
addl $0x2, %ecx
movw %cx, 0xc(%rax)
xorl %eax, %eax
testb $0x1, %al
jne 0x3232e
jmp 0x32370
movq -0x1f0(%rbp), %rax
movq (%rax), %rax
leaq -0x2c3f(%rip), %rcx     # 0x2f700
subq $0x1, %rcx
movq (%rax,%rcx), %rax
movq %rax, -0x230(%rbp)
jmp 0x32380
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0xe4c0
jmp 0x323ab
leaq -0x2c77(%rip), %rax     # 0x2f700
movq %rax, -0x230(%rbp)
jmp 0x32380
movq -0x1f0(%rbp), %rdi
movq -0x230(%rbp), %rax
movzwl -0x16(%rbp), %esi
callq *%rax
jmp 0x32396
leaq -0x1a0(%rbp), %rdi
callq 0xe4c0
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq -0x1b0(%rbp), %rdi
callq 0xe700
nopw (%rax,%rax)