// File: ksherlock[P]wdc-utils/disassembler.cpp
// Function: disassembler::print()
void disassembler::print() {


	if (_size) {
		std::string tmp;

		switch(_mode & 0xf000) {
			case mRelative: {

				uint32_t pc = _pc + 1 + _size + _arg;

				if ((_size == 1) && (_arg & 0x80))
					pc += 0xff00;
				pc &= 0xffff;


				// it would be really fancy if it checked for a label name @pc...
				tmp = label_for_address(pc);
				if (tmp.empty()) tmp = to_x(pc, 4, '$');
				break;
			}
			case mBlockMove: {
				// todo -- verify order.
				tmp = to_x((_arg >> 8) & 0xff, 2, '$')
					+ ","
					+ to_x((_arg >> 0) & 0xff, 2, '$');
				break;
			}
			case mDP:
			case mDPI:
			case mDPIL:
				tmp = label_for_zp(_arg);
				if (tmp.empty()) tmp = to_x(_arg, _size * 2, '$');
				break;

			//case mImmediate:
			case mAbsolute:
			case mAbsoluteI:
			case mAbsoluteIL:
			case mAbsoluteLong:
				tmp = label_for_address(_arg);
				if (tmp.empty()) tmp = to_x(_arg, _size * 2, '$');
				break;

			default:
				tmp = to_x(_arg, _size * 2, '$');
				break;
		}
		print(tmp);
		return;

	}

	std::string line;




	indent_to(line, kOpcodeTab);
	line.append(&opcodes[_op * 3], 3);

	if (_mode == mImpliedA && (_traits & explicit_implied_a)) {
		indent_to(line, kOperandTab);
		line.append("a");
	}


	hexdump(line);
	line.push_back('\n');
	fputs(line.c_str(), stdout);
	_pc += _size + 1;
	reset();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpl $0x0, 0x10(%rax)
je 0xe66d
leaq -0x28(%rbp), %rdi
callq 0x3380
movq -0x1c8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0xf000, %eax           # imm = 0xF000
movl %eax, -0x1cc(%rbp)
subl $0x2000, %eax           # imm = 0x2000
je 0xe57a
jmp 0xe27f
movl -0x1cc(%rbp), %eax
subl $0x3000, %eax           # imm = 0x3000
je 0xe57a
jmp 0xe292
movl -0x1cc(%rbp), %eax
subl $0x4000, %eax           # imm = 0x4000
je 0xe57a
jmp 0xe2a5
movl -0x1cc(%rbp), %eax
subl $0x5000, %eax           # imm = 0x5000
je 0xe57a
jmp 0xe2b8
movl -0x1cc(%rbp), %eax
subl $0x6000, %eax           # imm = 0x6000
je 0xe4f0
jmp 0xe2cb
movl -0x1cc(%rbp), %eax
subl $0x7000, %eax           # imm = 0x7000
je 0xe4f0
jmp 0xe2de
movl -0x1cc(%rbp), %eax
subl $0x8000, %eax           # imm = 0x8000
je 0xe4f0
jmp 0xe2f1
movl -0x1cc(%rbp), %eax
subl $0x9000, %eax           # imm = 0x9000
je 0xe316
jmp 0xe300
movl -0x1cc(%rbp), %eax
subl $0xa000, %eax           # imm = 0xA000
je 0xe3dc
jmp 0xe601
movq -0x1c8(%rbp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
addl 0x10(%rax), %ecx
addl 0x24(%rax), %ecx
movl %ecx, -0x2c(%rbp)
cmpl $0x1, 0x10(%rax)
jne 0xe351
movq -0x1c8(%rbp), %rax
movl 0x24(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xe351
movl -0x2c(%rbp), %eax
addl $0xff00, %eax           # imm = 0xFF00
movl %eax, -0x2c(%rbp)
movq -0x1c8(%rbp), %rsi
movzwl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edx
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq -0x50(%rbp), %rdi
callq *%rax
jmp 0xe371
leaq -0x28(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3310
leaq -0x50(%rbp), %rdi
callq 0x3160
leaq -0x28(%rbp), %rdi
callq 0x3430
testb $0x1, %al
jne 0xe396
jmp 0xe3d7
movl -0x2c(%rbp), %esi
leaq -0x80(%rbp), %rdi
movl $0x4, %edx
movl $0x24, %ecx
callq 0xcb90
jmp 0xe3ae
leaq -0x28(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3310
leaq -0x80(%rbp), %rdi
callq 0x3160
jmp 0xe3d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xe65f
jmp 0xe63f
movq -0x1c8(%rbp), %rax
movzbl 0x25(%rax), %esi
leaq -0xe0(%rbp), %rdi
movl $0x2, %edx
movl $0x24, %ecx
callq 0xcb90
jmp 0xe3ff
leaq 0xd85c(%rip), %rdx      # 0x1bc62
leaq -0xc0(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x8410
jmp 0xe41b
movq -0x1c8(%rbp), %rax
movzbl 0x24(%rax), %esi
leaq -0x100(%rbp), %rdi
movl $0x2, %edx
movl $0x24, %ecx
callq 0xcb90
jmp 0xe43e
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x8340
jmp 0xe45a
leaq -0x28(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x3310
leaq -0xa0(%rbp), %rdi
callq 0x3160
leaq -0x100(%rbp), %rdi
callq 0x3160
leaq -0xc0(%rbp), %rdi
callq 0x3160
leaq -0xe0(%rbp), %rdi
callq 0x3160
jmp 0xe63f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xe4df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xe4d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x3160
leaq -0xc0(%rbp), %rdi
callq 0x3160
leaq -0xe0(%rbp), %rdi
callq 0x3160
jmp 0xe65f
movq -0x1c8(%rbp), %rsi
movl 0x24(%rsi), %edx
movq (%rsi), %rax
movq 0x28(%rax), %rax
leaq -0x120(%rbp), %rdi
callq *%rax
jmp 0xe50c
leaq -0x28(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3310
leaq -0x120(%rbp), %rdi
callq 0x3160
leaq -0x28(%rbp), %rdi
callq 0x3430
testb $0x1, %al
jne 0xe537
jmp 0xe575
movq -0x1c8(%rbp), %rax
movl 0x10(%rax), %edx
movl 0x24(%rax), %esi
addl %edx, %edx
leaq -0x140(%rbp), %rdi
movl $0x24, %ecx
callq 0xcb90
jmp 0xe559
leaq -0x28(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x3310
leaq -0x140(%rbp), %rdi
callq 0x3160
jmp 0xe63f
movq -0x1c8(%rbp), %rsi
movl 0x24(%rsi), %edx
movq (%rsi), %rax
movq 0x20(%rax), %rax
leaq -0x160(%rbp), %rdi
callq *%rax
jmp 0xe596
leaq -0x28(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x3310
leaq -0x160(%rbp), %rdi
callq 0x3160
leaq -0x28(%rbp), %rdi
callq 0x3430
testb $0x1, %al
jne 0xe5c1
jmp 0xe5ff
movq -0x1c8(%rbp), %rax
movl 0x10(%rax), %edx
movl 0x24(%rax), %esi
addl %edx, %edx
leaq -0x180(%rbp), %rdi
movl $0x24, %ecx
callq 0xcb90
jmp 0xe5e3
leaq -0x28(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x3310
leaq -0x180(%rbp), %rdi
callq 0x3160
jmp 0xe63f
movq -0x1c8(%rbp), %rax
movl 0x10(%rax), %edx
movl 0x24(%rax), %esi
addl %edx, %edx
leaq -0x1a0(%rbp), %rdi
movl $0x24, %ecx
callq 0xcb90
jmp 0xe623
leaq -0x28(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x3310
leaq -0x1a0(%rbp), %rdi
callq 0x3160
movq -0x1c8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xdda0
jmp 0xe651
leaq -0x28(%rbp), %rdi
callq 0x3160
jmp 0xe792
leaq -0x28(%rbp), %rdi
callq 0x3160
jmp 0xe79b
leaq -0x1c0(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3380
movq -0x1d8(%rbp), %rdi
movl $0x14, %esi
callq 0xcb10
jmp 0xe693
movq -0x1c8(%rbp), %rax
movzbl 0xc(%rax), %ecx
movl %ecx, %eax
leal (%rax,%rax,2), %eax
leaq 0xd266(%rip), %rsi      # 0x1b910
addq %rax, %rsi
leaq -0x1c0(%rbp), %rdi
movl $0x3, %edx
callq 0x3070
jmp 0xe6c0
movq -0x1c8(%rbp), %rax
cmpl $0xb000, 0x14(%rax)     # imm = 0xB000
jne 0xe726
movq -0x1c8(%rbp), %rax
movl 0x34(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xe726
leaq -0x1c0(%rbp), %rdi
movl $0x1e, %esi
callq 0xcb10
jmp 0xe6f5
leaq 0xd53f(%rip), %rsi      # 0x1bc3b
leaq -0x1c0(%rbp), %rdi
callq 0x34b0
jmp 0xe70a
jmp 0xe726
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1c0(%rbp), %rdi
callq 0x3160
jmp 0xe79b
movq -0x1c8(%rbp), %rdi
leaq -0x1c0(%rbp), %rsi
callq 0xd5e0
jmp 0xe73b
leaq -0x1c0(%rbp), %rdi
movl $0xa, %esi
callq 0x3230
jmp 0xe74e
leaq -0x1c0(%rbp), %rdi
callq 0x30f0
movq %rax, %rdi
movq 0x1685c(%rip), %rax     # 0x24fc0
movq (%rax), %rsi
callq 0x32e0
jmp 0xe76e
movq -0x1c8(%rbp), %rdi
movl 0x10(%rdi), %eax
addl $0x1, %eax
addl 0x20(%rdi), %eax
movl %eax, 0x20(%rdi)
callq 0xd060
leaq -0x1c0(%rbp), %rdi
callq 0x3160
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)