// File: /workspace/github_c_makefile_star2_O0/calmopyrin[P]tedplay/./Cpu.h
// Function: CPU::SBC(unsigned char)
inline void CPU::SBC(const unsigned char value)
{
	if (ST&0x08) { // if in decimal mode
		unsigned int bin_sbc = (AC - value - (1-(ST&0x01)));
		unsigned int dec_sbc = (AC & 0x0F) - (value & 0x0F) - (1-(ST&0x01));
		// Calculate the upper nybble.
		// fix upper nybble
		if (dec_sbc&0x10)
			dec_sbc = ((dec_sbc-6)&0x0F) | ((AC&0xF0) - (value&0xF0) - 0x10);
		else
			dec_sbc = (dec_sbc&0x0F) | ((AC&0xF0) - (value&0xF0));
		
		if (dec_sbc&0x100)
			dec_sbc-= 0x60;

		// all flags depend on the normal SBC...
		(bin_sbc<0x100) ? ST|=0x01 : ST&=0xFE ; // carry flag
		SETFLAGS_ZN( bin_sbc & 0xFF );
		((AC^bin_sbc)&0x80 && (AC^value)&0x80 ) ? SetVFlag() : ClearVFlag(); // V flag

		AC=(unsigned char) dec_sbc;

	} else {
		unsigned int bin_sbc = (AC - value - (1-(ST&0x01)));
		(bin_sbc<0x100) ? ST|=0x01 : ST&=0xFE;
		(((AC ^ value) & 0x80) && ((AC ^ bin_sbc) & 0x80) ) ? SetVFlag() : ClearVFlag();
		AC=(unsigned char) bin_sbc;
		SETFLAGS_ZN(AC);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movb %sil, %al
movq %rdi, -0x8(%rbp)
movb %al, -0x9(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl 0x18(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x13578
movq -0x20(%rbp), %rcx
movzbl 0x1c(%rcx), %eax
movzbl -0x9(%rbp), %edx
subl %edx, %eax
movl 0x18(%rcx), %esi
andl $0x1, %esi
movl $0x1, %edx
subl %esi, %edx
subl %edx, %eax
movl %eax, -0x10(%rbp)
movzbl 0x1c(%rcx), %eax
andl $0xf, %eax
movzbl -0x9(%rbp), %edx
andl $0xf, %edx
subl %edx, %eax
movl 0x18(%rcx), %edx
andl $0x1, %edx
movl $0x1, %ecx
subl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x13483
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %eax
subl $0x6, %eax
andl $0xf, %eax
movzbl 0x1c(%rcx), %ecx
andl $0xf0, %ecx
movzbl -0x9(%rbp), %edx
andl $0xf0, %edx
subl %edx, %ecx
subl $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
jmp 0x134a8
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %eax
andl $0xf, %eax
movzbl 0x1c(%rcx), %ecx
andl $0xf0, %ecx
movzbl -0x9(%rbp), %edx
andl $0xf0, %edx
subl %edx, %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x134be
movl -0x14(%rbp), %eax
subl $0x60, %eax
movl %eax, -0x14(%rbp)
cmpl $0x100, -0x10(%rbp)     # imm = 0x100
jae 0x134dd
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x18, %rcx
movl 0x18(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x134f4
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x18, %rcx
movl 0x18(%rax), %ecx
andl $0xfe, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x7d, %ecx
movl -0x10(%rbp), %edx
andl $0xff, %edx
cmpl $0x0, %edx
sete %dl
andb $0x1, %dl
movzbl %dl, %edx
shll %edx
orl %edx, %ecx
movl -0x10(%rbp), %edx
andl $0xff, %edx
andl $0x80, %edx
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movzbl 0x1c(%rax), %eax
xorl -0x10(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1355f
movq -0x20(%rbp), %rax
movzbl 0x1c(%rax), %eax
movzbl -0x9(%rbp), %ecx
xorl %ecx, %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x1355f
movq -0x20(%rbp), %rdi
callq 0x13650
jmp 0x13569
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
movb %cl, 0x1c(%rax)
jmp 0x13643
movq -0x20(%rbp), %rcx
movzbl 0x1c(%rcx), %eax
movzbl -0x9(%rbp), %edx
subl %edx, %eax
movl 0x18(%rcx), %edx
andl $0x1, %edx
movl $0x1, %ecx
subl %edx, %ecx
subl %ecx, %eax
movl %eax, -0x18(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jae 0x135b7
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x18, %rcx
movl 0x18(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x135ce
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x18, %rcx
movl 0x18(%rax), %ecx
andl $0xfe, %ecx
movl %ecx, 0x18(%rax)
movq -0x20(%rbp), %rax
movzbl 0x1c(%rax), %eax
movzbl -0x9(%rbp), %ecx
xorl %ecx, %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x13606
movq -0x20(%rbp), %rax
movzbl 0x1c(%rax), %eax
xorl -0x18(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x13606
movq -0x20(%rbp), %rdi
callq 0x13650
jmp 0x13610
movq -0x20(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0x20(%rbp), %rax
movl -0x18(%rbp), %ecx
movb %cl, 0x1c(%rax)
movl 0x18(%rax), %ecx
andl $0x7d, %ecx
movzbl 0x1c(%rax), %edx
cmpl $0x0, %edx
sete %dl
andb $0x1, %dl
movzbl %dl, %edx
shll %edx
orl %edx, %ecx
movzbl 0x1c(%rax), %edx
andl $0x80, %edx
orl %edx, %ecx
movl %ecx, 0x18(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)