fix sbc carry flag

This commit is contained in:
Matthew Berry 2020-10-24 11:33:04 -07:00
parent c589e8f6ef
commit 5a298dd41c

View file

@ -195,10 +195,10 @@ class CPU
# Subtract two values with carry
def sbc(operand_1 : Word, operand_2 : Word, set_conditions) : Word
log "sbc - operand_1:#{hex_str operand_1}, operand_2:#{hex_str operand_2}"
res = operand_1 &- operand_2 &+ @cpsr.carry.to_unsafe &- 1
res = operand_1 &- operand_2 &- 1 &+ @cpsr.carry.to_unsafe
if set_conditions
@cpsr.overflow = bit?((operand_1 ^ operand_2) & (operand_1 ^ res), 31)
@cpsr.carry = operand_1 >= operand_2
@cpsr.carry = operand_1 >= operand_2.to_u64 + 1 - @cpsr.carry.to_unsafe
@cpsr.zero = res == 0
@cpsr.negative = bit?(res, 31)
end