// File: rockytriton[P]dreamsys_emu_gb/src/op_handler.cpp
// Function: dsemu::cpu::handleINC(dsemu::cpu::OpCode const&)
int handleINC(const OpCode &op) {
    ushort val = 0;
    ushort prev = 0;

    switch(op.params[0]) {
        case A: prev = regAF.hi++; val = regAF.hi; break;
        case B: prev = regBC.hi++; val = regBC.hi; break;
        case C: prev = regBC.lo++; val = regBC.lo; break;
        case D: prev = regDE.hi++; val = regDE.hi; break;
        case E: prev = regDE.lo++; val = regDE.lo; break;
        case H: prev = regHL.hi++; val = regHL.hi; break;
        case L: prev = regHL.lo++; val = regHL.lo; break;
        case BC: prev = (*getReg16Pointer(regBC))++; val = (getReg16Value(regBC));  return 0;
        case DE: prev = (*getReg16Pointer(regDE))++; val = (getReg16Value(regDE)); return 0;
        case SP: prev = (*getReg16Pointer(regSP))++; val = (getReg16Value(regSP)); return 0;
        case HL: {
            if (op.mode == ATypeA) {
                byte b = bus::read((getReg16Value(regHL)));
                prev = b++;
                bus::write((getReg16Value(regHL)), b);
                val = b;

            } else {
                prev = (*getReg16Pointer(regHL))++; 
                val = (getReg16Value(regHL)); 
                return 0;
            }
        } break;
        default:
            cout << "INVALID INC FLAG" << endl;
            exit(-1);
            return 0;
    }

    setFlag(FlagZ, val == 0);
    setFlag(FlagN, 0);
    setFlag(FlagH, (prev & 0xF) == 0xF);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movw $0x0, -0x12(%rbp)
movw $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq %rax, -0x20(%rbp)
subq $0xa, %rax
ja 0x1c888
movq -0x20(%rbp), %rax
leaq 0x7da4(%rip), %rcx      # 0x2437c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x12fa8(%rip), %rax     # 0x2f590
movb 0x1(%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12f99(%rip), %rcx     # 0x2f590
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12f88(%rip), %rax     # 0x2f590
movzbl 0x1(%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12f76(%rip), %rax     # 0x2f592
movb 0x1(%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12f67(%rip), %rcx     # 0x2f592
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12f56(%rip), %rax     # 0x2f592
movzbl 0x1(%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12f42(%rip), %rax     # 0x2f592
movb (%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12f34(%rip), %rcx     # 0x2f592
movb %dl, (%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12f24(%rip), %rax     # 0x2f592
movzbl (%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12f13(%rip), %rax     # 0x2f594
movb 0x1(%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12f04(%rip), %rcx     # 0x2f594
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12ef3(%rip), %rax     # 0x2f594
movzbl 0x1(%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12edf(%rip), %rax     # 0x2f594
movb (%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12ed1(%rip), %rcx     # 0x2f594
movb %dl, (%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12ec1(%rip), %rax     # 0x2f594
movzbl (%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12eb0(%rip), %rax     # 0x2f596
movb 0x1(%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12ea1(%rip), %rcx     # 0x2f596
movb %dl, 0x1(%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12e90(%rip), %rax     # 0x2f596
movzbl 0x1(%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12e7c(%rip), %rax     # 0x2f596
movb (%rax), %al
movb %al, %dl
addb $0x1, %dl
leaq 0x12e6e(%rip), %rcx     # 0x2f596
movb %dl, (%rcx)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12e5e(%rip), %rax     # 0x2f596
movzbl (%rax), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c8b4
leaq 0x12e47(%rip), %rdi     # 0x2f592
callq 0x153e0
movq %rax, %rcx
movw (%rcx), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, (%rcx)
movw %ax, -0x14(%rbp)
leaq 0x12e27(%rip), %rdi     # 0x2f592
callq 0x15070
movw %ax, -0x12(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x1c8fe
leaq 0x12e0d(%rip), %rdi     # 0x2f594
callq 0x153e0
movq %rax, %rcx
movw (%rcx), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, (%rcx)
movw %ax, -0x14(%rbp)
leaq 0x12ded(%rip), %rdi     # 0x2f594
callq 0x15070
movw %ax, -0x12(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x1c8fe
leaq 0x12dd9(%rip), %rdi     # 0x2f59c
callq 0x153e0
movq %rax, %rcx
movw (%rcx), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, (%rcx)
movw %ax, -0x14(%rbp)
leaq 0x12db9(%rip), %rdi     # 0x2f59c
callq 0x15070
movw %ax, -0x12(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x1c8fe
movq -0x10(%rbp), %rax
cmpl $0xc, 0x18(%rax)
jne 0x1c84d
leaq 0x12d8d(%rip), %rdi     # 0x2f596
callq 0x15070
movzwl %ax, %edi
callq 0x13450
movb %al, -0x15(%rbp)
movb -0x15(%rbp), %al
movb %al, %cl
addb $0x1, %cl
movb %cl, -0x15(%rbp)
movzbl %al, %eax
movw %ax, -0x14(%rbp)
leaq 0x12d64(%rip), %rdi     # 0x2f596
callq 0x15070
movzwl %ax, %edi
movzbl -0x15(%rbp), %esi
callq 0x13590
movzbl -0x15(%rbp), %eax
movw %ax, -0x12(%rbp)
jmp 0x1c886
leaq 0x12d42(%rip), %rdi     # 0x2f596
callq 0x153e0
movq %rax, %rcx
movw (%rcx), %ax
movw %ax, %dx
addw $0x1, %dx
movw %dx, (%rcx)
movw %ax, -0x14(%rbp)
leaq 0x12d22(%rip), %rdi     # 0x2f596
callq 0x15070
movw %ax, -0x12(%rbp)
movl $0x0, -0x4(%rbp)
jmp 0x1c8fe
jmp 0x1c8b4
movq 0x12741(%rip), %rdi     # 0x2efd0
leaq 0x7c76(%rip), %rsi      # 0x2450c
callq 0x32c0
movq %rax, %rdi
movq 0x1270b(%rip), %rsi     # 0x2efb0
callq 0x3310
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3390
movzwl -0x12(%rbp), %eax
cmpl $0x0, %eax
sete %al
movzbl %al, %esi
andl $0x1, %esi
movl $0x7, %edi
callq 0x1da80
movl $0x6, %edi
xorl %esi, %esi
callq 0x1da80
movzwl -0x14(%rbp), %eax
andl $0xf, %eax
cmpl $0xf, %eax
sete %al
movzbl %al, %esi
andl $0x1, %esi
movl $0x5, %edi
callq 0x1da80
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)