public virtual void Execute(ProgrammingModel model, Memory memory, byte argument) { var accumulator = model.GetRegister(RegisterName.A); accumulator.SetValue((byte)accumulator.GetValue() & argument); RegisterUtils.SetZeroFlag(model, RegisterName.A); RegisterUtils.SetNegativeFlag(model, RegisterName.A); }
public void AndsWithTheAccumulator() { var model = new ProgrammingModel(); var accumulator = model.GetRegister(RegisterName.A); accumulator.SetValue(0xA); new And().Execute(model, null, 0x8); Assert.That(accumulator.GetValue(), Is.EqualTo(0x8)); }
private static void InitializeForEor(ProgrammingModel model, Memory memory) { model.GetRegister(RegisterName.A).SetValue(0x0A); model.GetRegister(RegisterName.X).SetValue(0x10); model.GetRegister(RegisterName.Y).SetValue(0x10); memory.SetValue(0x1000, 0xFF); memory.SetValue(0x10, 0xFF); memory.SetValue(0x21, 0x10); }
public void FormatsTheDefaultRegisters() { var model = new ProgrammingModel(); var expected = string.Join("\n", "A:0x00 - X:0x00 - Y:0x00 - S:00100000", "SP:0xFF - PC:0x0000 NV-BDIZC"); Assert.That(RegisterFormatter.Display(model), Is.EqualTo(expected)); }
public void ClearsTheCarryFlag() { var model = new ProgrammingModel(); model.CarryFlag = true; new Clc().Execute(model, null, 0); Assert.That(model.CarryFlag, Is.False, "The carry flag was not cleared, which is not expected."); }
private static ushort IndexedIndirectAddressFor(ProgrammingModel model, Memory memory, RegisterName register, ushort operand) { var zeroPageAddress = OffsetAddressFor(model, register, operand); var effectiveAddressLow = memory.GetValue(zeroPageAddress); var effectiveAddressHi = memory.GetValue((ushort)(zeroPageAddress + 1)); return (ushort)(effectiveAddressHi << 8 | effectiveAddressLow); }
public void SetUp() { instruction = new InstructionTestDouble(); var registry = new Registry { { 0x00, opcode, instruction, AddressingMode.Implied} }; model = new ProgrammingModel(); memory = new Memory(); executor = new Executor(registry, model, memory); }
public void VerifyValuesOfZeroFlag(int initialValue, bool expectedResult) { var model = new ProgrammingModel(); model.GetRegister(RegisterName.A).SetValue(initialValue); model.ZeroFlag = !expectedResult; new And().Execute(model, null, 0x01); Assert.That(model.ZeroFlag, Is.EqualTo(expectedResult)); }
public void IncrementsTheValueInRegisterY() { const int initialValue = 42; var model = new ProgrammingModel(); model.GetRegister(RegisterName.Y).SetValue(initialValue); var instruction = new Iny(); instruction.Execute(model, null, 0); Assert.That(model.GetRegister(RegisterName.Y).GetValue(), Is.EqualTo(initialValue + 1)); }
public void VerifyValuesOfZeroFlag(int initialValue, bool expectedResult) { var model = new ProgrammingModel(); model.GetRegister(RegisterName.Y).SetValue(initialValue); model.ZeroFlag = !expectedResult; var instruction = new Iny(); instruction.Execute(model, null, 0); Assert.That(model.ZeroFlag, Is.EqualTo(expectedResult)); }
public void AddsWithTheAccumulatorIncludingCarry() { var model = new ProgrammingModel(); var accumulator = model.GetRegister(RegisterName.A); accumulator.SetValue(0xA); var status = model.GetRegister(RegisterName.S); status.SetValue(status.GetValue() | 0x01); new Adc().Execute(model, null, 0x8); Assert.That(accumulator.GetValue(), Is.EqualTo(0x13)); }
public void Execute(ProgrammingModel model, Memory memory, byte argument) { var status = model.GetRegister(RegisterName.S); byte carry = (byte)(status.GetValue() & 0x01); var accumulator = model.GetRegister(RegisterName.A); var previousValue = (byte)accumulator.GetValue(); accumulator.SetValue(previousValue + argument+ carry); RegisterUtils.SetZeroFlag(model, RegisterName.A); RegisterUtils.SetNegativeFlag(model, RegisterName.A); RegisterUtils.SetOverflowFlag(model, previousValue); RegisterUtils.SetCarryFlag(model, previousValue); }
public void InstructionWorksEndToEnd(SetUp setup, string input, string expectedOutput) { var model = new ProgrammingModel(); var memory = new Memory(); setup(model, memory); var repl = new Repl(model, memory); if (!repl.TryRead(input)) Assert.Fail(string.Format("Unable to read assembly input: '{0}'", input)); if (!repl.Execute()) Assert.Fail(string.Format("Unable to execute input: '{0}'", input)); Assert.That(repl.PrintRegisters(), Is.StringContaining(expectedOutput)); }
public static string Display(ProgrammingModel model) { var registerFormat = string.Join("\n", "A:0x{0:X2} - X:0x{1:X2} - Y:0x{2:X2} - S:{3}", "SP:0x{4:X2} - PC:0x{5:X4} NV-BDIZC"); return(string.Format(registerFormat, model.GetRegister(RegisterName.A).GetValue(), model.GetRegister(RegisterName.X).GetValue(), model.GetRegister(RegisterName.Y).GetValue(), Convert.ToString(model.GetRegister(RegisterName.P).GetValue(), 2).PadLeft(8, '0'), model.GetRegister(RegisterName.S).GetValue(), model.GetRegister(RegisterName.PC).GetValue())); }
public static bool CrossesPageBoundary(ProgrammingModel model, AddressingMode mode, ushort operand) { if (mode == AddressingMode.AbsoluteX) { var address = OffsetAddressFor(model, RegisterName.X, operand); return (operand & 0xFF00) != (address & 0xFF00); } else if (mode == AddressingMode.AbsoluteY) { var address = OffsetAddressFor(model, RegisterName.Y, operand); return (operand & 0xFF00) != (address & 0xFF00); } return false; }
public static byte ArgumentFor(ProgrammingModel model, Memory memory, AddressingMode mode, ushort operand) { ushort address = 0; if (mode == AddressingMode.Immediate) return (byte)operand; else if (mode == AddressingMode.Absolute || mode == AddressingMode.Zeropage) address = operand; else if (mode == AddressingMode.AbsoluteX || mode == AddressingMode.ZeropageX) address = OffsetAddressFor(model, RegisterName.X, operand); else if (mode == AddressingMode.AbsoluteY || mode == AddressingMode.ZeropageY) address = OffsetAddressFor(model, RegisterName.Y, operand); else if (mode == AddressingMode.IndexedIndirectX) address = IndexedIndirectAddressFor(model, memory, RegisterName.X, operand); else if (mode == AddressingMode.IndexedIndirectY) address = IndexedIndirectAddressFor(model, memory, RegisterName.Y, operand); return memory.GetValue(address); }
public void SetUp() { const byte expectedCode = 0xEA; // Nop opcode var model = new ProgrammingModel(); model.GetRegister(RegisterName.PC).SetValue(InstructionAddress); memory = new Memory(); memory.SetValue(InstructionAddress, expectedCode); instruction = new InstructionTestDouble(); var registry = new Registry { { expectedCode, Opcode.Nop, instruction, AddressingMode.Absolute } }; var fetcher = new Fetcher(model, memory); var decoder = new Decoder(registry); var executor = new Executor(registry, model, memory); loop = new CoreLoop(fetcher, decoder, executor); }
public void Execute(ProgrammingModel model, Memory memory, byte argument) { model.CarryFlag = false; }
public virtual void Execute(ProgrammingModel model, Memory memory, byte argument) { }
public virtual void Execute(ProgrammingModel model, Memory memory, byte argument) { ExecuteCalled = true; ProvidedArgument = (byte)argument; }
private static ushort OffsetAddressFor(ProgrammingModel model, RegisterName register, ushort operand) { return (ushort)(operand + model.GetRegister(register).GetValue()); }
public virtual void Execute(ProgrammingModel model, Memory memory, byte argument) { ExecuteCalled = true; ArgumentUsed = argument; }
public void SetUp() { model = new ProgrammingModel(); }
public void SetUp() { model = new ProgrammingModel(); memory = new Memory(); fetcher = new Fetcher(model, memory); }
private static void Empty(ProgrammingModel model, Memory memory) { }
public void SetUp() { model = new ProgrammingModel(); memory = new Memory(); }
// Use this for initialization private void Start() { model = manager.GetComponent <Emulator>().model; }
public void Awake() { model = new ProgrammingModel(); memory = new Memory(); repl = new Repl(model, memory); }