public override void Execute(CPUState state, Bus bus) { if (state.HasStatusFlag(StatusFlag.Zero)) { state.PC = (ushort)CalculateEffectiveAddress(state, bus); } }
public override void Execute(CPUState state, Bus bus) { byte operandValue = GetOperandValue(state, bus); int result = state.Accumulator + operandValue + (state.HasStatusFlag(StatusFlag.Carry) ? 1 : 0); CheckOverflowFlag(state, state.Accumulator, operandValue, result); // Need to work here with integer result as we need to look at the 9th bit for carry state.ChangeStatusFlag(StatusFlag.Carry, (result & 0x100) != 0); state.Accumulator = (byte)result; CheckNegativeFlag(state, state.Accumulator); CheckZeroFlag(state, state.Accumulator); }
public override void Execute(CPUState state, Bus bus) { // Same as ADC, just used one's complement of the operand byte operandValue = (byte)~GetOperandValue(state, bus); int result = state.Accumulator + operandValue + (state.HasStatusFlag(StatusFlag.Carry) ? 1 : 0); // TODO: learn how this works: http://www.righto.com/2012/12/the-6502-overflow-flag-explained.html CheckOverflowFlag(state, state.Accumulator, operandValue, result); // Need to work here with integer result as we need to look at the 9th bit for carry state.ChangeStatusFlag(StatusFlag.Carry, (result & 0x100) != 0); state.Accumulator = (byte)result; CheckNegativeFlag(state, state.Accumulator); CheckZeroFlag(state, state.Accumulator); }
public override void Execute(CPUState state, Bus bus) { byte result; int carryBitmask = state.HasStatusFlag(StatusFlag.Carry) ? 0x80 : 0; if (Instruction.AddressMode != AddressMode.Accumulator) { int effectiveAddress = CalculateEffectiveAddress(state, bus); byte operandValue = bus.Read(effectiveAddress); state.ChangeStatusFlag(StatusFlag.Carry, (operandValue & 1) == 1); // The lowest bit is displaced by the left shift and stored as a carry flag result = (byte)((operandValue >> 1) | carryBitmask); // Set the carry bit in the shifted value via bitwise OR bus.Write(effectiveAddress, result); } else { state.ChangeStatusFlag(StatusFlag.Carry, (state.Accumulator & 1) == 1); // The lowest bit is displaced by the left shift and stored as a carry flag result = (byte)((state.Accumulator >> 1) | carryBitmask); // Set the carry bit in the shifted value via bitwise OR state.Accumulator = result; } CheckZeroFlag(state, result); CheckNegativeFlag(state, result); }