// File: Escapingbug[P]mos6502-emulator-debugging/mos6502.cpp
// Function: mos6502::DebugCommandline(unsigned short)
void mos6502::DebugCommandline(uint16_t src) {
  std::cout << "Break at " << std::hex << src << std::endl;

  while (1) {
	std::cout << "Debug> ";
	std::string cmd;
	std::getline(std::cin, cmd);

	std::vector<std::string> args;

	SplitString(cmd, args, " ");

	if (args.size() < 1) {
	  std::cout << "Incorrect commands" << std::endl;
	  continue;
	}

	if (args[0] == "c") {
	  std::cout << "continue.." << std::endl;
	  break;
	}

	auto iter = commands.find(args[0][0]);
	if (iter != commands.end()) {
	  auto func = iter->second;
	  (this->*func)(args);
	}
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movw %si, %ax
movq %rdi, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0xe2d8(%rip), %rdi      # 0x10fd0
leaq 0x9318(%rip), %rsi      # 0xc017
callq 0x21f0
movq %rax, %rdi
leaq 0x6952(%rip), %rsi      # 0x9660
callq 0x20a0
movq %rax, %rdi
movzwl -0xa(%rbp), %esi
callq 0x2330
movq %rax, %rdi
movq 0xe28f(%rip), %rsi      # 0x10fb8
callq 0x2240
movq 0xe29b(%rip), %rdi      # 0x10fd0
leaq 0x92e5(%rip), %rsi      # 0xc021
callq 0x21f0
leaq -0x30(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x22a0
movq -0xb0(%rbp), %rsi
movq 0xe281(%rip), %rdi      # 0x10fe0
callq 0x2060
jmp 0x2d66
leaq -0x58(%rbp), %rdi
callq 0x9690
leaq -0x79(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x2350
movq -0xb8(%rbp), %rdx
leaq 0x929a(%rip), %rsi      # 0xc027
leaq -0x78(%rbp), %rdi
callq 0x96b0
jmp 0x2d98
leaq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x3070
jmp 0x2dab
leaq -0x78(%rbp), %rdi
callq 0x2120
leaq -0x79(%rbp), %rdi
callq 0x2260
leaq -0x58(%rbp), %rdi
callq 0x9760
cmpq $0x1, %rax
jae 0x2e60
movq 0xe1f9(%rip), %rdi      # 0x10fd0
leaq 0x924b(%rip), %rsi      # 0xc029
callq 0x21f0
movq %rax, -0xc0(%rbp)
jmp 0x2dec
movq -0xc0(%rbp), %rdi
movq 0xe1be(%rip), %rsi      # 0x10fb8
callq 0x2240
jmp 0x2e01
movl $0x2, -0x80(%rbp)
jmp 0x3011
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x3053
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x2e41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2120
leaq -0x79(%rbp), %rdi
callq 0x2260
jmp 0x304a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x304a
xorl %eax, %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x97b0
movq %rax, %rdi
leaq 0x91c5(%rip), %rsi      # 0xc03c
callq 0x9780
movb %al, -0xc1(%rbp)
jmp 0x2e84
movb -0xc1(%rbp), %al
testb $0x1, %al
jne 0x2e90
jmp 0x2ecd
movq 0xe139(%rip), %rdi      # 0x10fd0
leaq 0x91a0(%rip), %rsi      # 0xc03e
callq 0x21f0
movq %rax, -0xd0(%rbp)
jmp 0x2eac
movq -0xd0(%rbp), %rdi
movq 0xe0fe(%rip), %rsi      # 0x10fb8
callq 0x2240
jmp 0x2ec1
movl $0x3, -0x80(%rbp)
jmp 0x3011
movq -0xa8(%rbp), %rax
addq $0x2068, %rax           # imm = 0x2068
movq %rax, -0xe8(%rbp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0xe0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x97b0
movq -0xe0(%rbp), %rsi
movq %rax, %rdi
callq 0x2380
movq %rax, -0xd8(%rbp)
jmp 0x2f0d
movq -0xd8(%rbp), %rsi
movq -0xe8(%rbp), %rdi
callq 0x97d0
movq %rax, -0xf0(%rbp)
jmp 0x2f29
movq -0xa8(%rbp), %rdi
movq -0xf0(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0x2068, %rdi           # imm = 0x2068
callq 0x9830
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x9800
testb $0x1, %al
jne 0x2f6d
jmp 0x300a
leaq -0x88(%rbp), %rdi
callq 0x9860
movq -0xa8(%rbp), %rcx
movq %rax, %rdx
movq 0x8(%rdx), %rax
movq 0x10(%rdx), %rdx
movq %rdx, -0x98(%rbp)
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x98(%rbp), %rdx
addq %rdx, %rcx
movq %rcx, -0xf8(%rbp)
andq $0x1, %rax
cmpq $0x0, %rax
je 0x2fe4
movq -0x100(%rbp), %rcx
movq -0xf8(%rbp), %rax
movq (%rax), %rax
subq $0x1, %rcx
movq (%rax,%rcx), %rax
movq %rax, -0x108(%rbp)
jmp 0x2ff2
movq -0x100(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0xf8(%rbp), %rdi
movq -0x108(%rbp), %rax
leaq -0x58(%rbp), %rsi
callq *%rax
jmp 0x3008
jmp 0x300a
movl $0x0, -0x80(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x9880
leaq -0x30(%rbp), %rdi
callq 0x2120
movl -0x80(%rbp), %eax
movl %eax, -0x10c(%rbp)
testl %eax, %eax
je 0x3045
jmp 0x3032
movl -0x10c(%rbp), %eax
subl $0x2, %eax
je 0x2d2e
jmp 0x3043
jmp 0x305e
jmp 0x2d2e
leaq -0x58(%rbp), %rdi
callq 0x9880
leaq -0x30(%rbp), %rdi
callq 0x2120
jmp 0x3067
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x2340