// File: /workspace/github_cpp_makefile_star2_O2/mdpkh[P]retro6k/src/fake6502.c
// Function: adc
static void adc() {
    penaltyop = 1;
    value = getvalue();
#ifdef NES_CPU
    result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY); // ORIGINAL BY MC
   
    carrycalc(result);
    zerocalc(result);
    overflowcalc(result, a, value);
    signcalc(result);
#else
    if (status & FLAG_DECIMAL) {
        // set or clear zero flag based on binary-mode result
        zerocalc((uint16_t)a + value + (uint16_t)(status & FLAG_CARRY));
        
        result = ((uint16_t)a & 0x0f) + ((uint16_t)value & 0x0f) + ((uint16_t)status & FLAG_CARRY); // MODIFIED BY MDPKH

        clearcarry();
        if (result > 0x09) {
            result = (result + 0x06) & 0x0f | 0x10;
        }
        result += ((uint16_t)a & 0xf0) + ((uint16_t)value & 0xf0); // MODIFIED BY MDPKH, PART 2 OF CALCULATION
        
        overflowcalc(result, a, value);
        signcalc(result);
        
        if (result > 0x9f) {
            result += 0x60;
            setcarry();
        }
        carrycalc(result);
        
        // clockticks6502++; // 65C02 only!
    } else {
        result = (uint16_t)a + value + (uint16_t)(status & FLAG_CARRY); // ORIGINAL BY MC
        
        carrycalc(result);
        zerocalc(result);
        overflowcalc(result, a, value);
        signcalc(result);
    }
#endif
    saveaccum(result);
}

// Assembly:
pushq %rax
movb $0x1, 0x810412(%rip)    # 0x820796
callq 0xff48
movw %ax, 0x810416(%rip)     # 0x8207a6
movzbl 0x8103fc(%rip), %esi    # 0x820793
movzbl 0x8103f2(%rip), %edx    # 0x820790
testb $0x8, %sil
jne 0x10413
movzwl %si, %ecx
andl $0x1, %ecx
movzwl %dx, %edx
addl %eax, %ecx
addl %edx, %ecx
movl %esi, %edi
andb $-0xa, %dil
orb $0x1, %sil
cmpw $0x100, %cx             # imm = 0x100
movzbl %dil, %edi
movzbl %sil, %esi
cmovbl %edi, %esi
movl %esi, %edi
orb $0x2, %dil
andb $-0xb, %sil
movzbl %dil, %edi
movzbl %sil, %esi
testb %cl, %cl
cmovel %edi, %esi
xorl %ecx, %edx
movl %ecx, %edi
xorl %eax, %edi
movl %esi, %eax
andb $-0x49, %al
orb $0x40, %sil
testb %dl, %dil
movzbl %al, %edx
movzbl %sil, %eax
cmovnsl %edx, %eax
movw %cx, 0x8103a4(%rip)     # 0x8207a8
testb %cl, %cl
js 0x104b3
andb $0x7f, %al
jmp 0x104b5
movzwl %dx, %edx
leal (%rax,%rdx), %ecx
movzwl %si, %r8d
andl $0x1, %r8d
movl %r8d, %edi
addb %cl, %dil
sete %dil
andb $-0x44, %sil
addb %dil, %dil
orb %sil, %dil
movl %edx, %ecx
andl $0xf, %ecx
movl %eax, %esi
andl $0xf, %esi
addl %r8d, %esi
leal (%rsi,%rcx), %r8d
addl %ecx, %esi
addl $0x6, %esi
andl $0xf, %esi
orl $0x10, %esi
cmpw $0xa, %r8w
cmovbl %r8d, %esi
movl %edx, %r8d
andl $-0x10, %r8d
movl %eax, %ecx
andl $0xf0, %ecx
addl %r8d, %ecx
addl %esi, %ecx
movw %cx, 0x810333(%rip)     # 0x8207a8
xorl %ecx, %edx
xorl %ecx, %eax
leal 0x40(%rdi), %esi
testb %dl, %al
movzbl %dil, %eax
movzbl %sil, %edx
cmovnsl %eax, %edx
movl %edx, %eax
andb $0x7e, %al
orb $-0x80, %dl
testb %cl, %cl
movzbl %al, %esi
movzbl %dl, %eax
cmovnsl %esi, %eax
cmpw $0xa0, %cx
jb 0x104b5
movzwl %cx, %ecx
addl $0x60, %ecx
movw %cx, 0x8102f9(%rip)     # 0x8207a8
orb $0x1, %al
jmp 0x104b5
orb $-0x80, %al
movb %al, 0x8102d8(%rip)     # 0x820793
movb %cl, 0x8102cf(%rip)     # 0x820790
popq %rax
retq