From d73afc9e566a664ec1c4885764245ed6862743be Mon Sep 17 00:00:00 2001 From: jnosek Date: Tue, 14 Jul 2020 13:54:00 -0400 Subject: [PATCH] TransferControl base unit tests --- AGC/Instructions/TransferControl.cs | 7 +-- AGC/Memory/MemoryWord.cs | 2 + .../Instructions/TransferControlTests.cs | 47 +++++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 Tests/AGC.Tests/Instructions/TransferControlTests.cs diff --git a/AGC/Instructions/TransferControl.cs b/AGC/Instructions/TransferControl.cs index 4cab903..61b9615 100644 --- a/AGC/Instructions/TransferControl.cs +++ b/AGC/Instructions/TransferControl.cs @@ -1,6 +1,4 @@ -using Apollo.Virtual.AGC.Math; - -namespace Apollo.Virtual.AGC.Instructions +namespace Apollo.Virtual.AGC.Instructions { /// /// TC - 0000 @@ -12,6 +10,9 @@ namespace Apollo.Virtual.AGC.Instructions public class TransferControl : IInstruction { private const ushort _code = 0x0; + private const ushort _instruction = _code << 12; + + public static ushort Encode(ushort address) => (ushort)(_instruction | address); public TransferControl(Processor cpu) { diff --git a/AGC/Memory/MemoryWord.cs b/AGC/Memory/MemoryWord.cs index f2c6f53..a80135c 100644 --- a/AGC/Memory/MemoryWord.cs +++ b/AGC/Memory/MemoryWord.cs @@ -1,12 +1,14 @@ using Apollo.Virtual.AGC.Math; using System.Diagnostics; using System.Threading.Tasks; +using System.Diagnostics; namespace Apollo.Virtual.AGC.Memory { /// /// Default 15-bit ones compliment memory word /// + [DebuggerDisplay("{Read()}")] public class MemoryWord : IWord { private MemoryBank bank; diff --git a/Tests/AGC.Tests/Instructions/TransferControlTests.cs b/Tests/AGC.Tests/Instructions/TransferControlTests.cs new file mode 100644 index 0000000..63fe590 --- /dev/null +++ b/Tests/AGC.Tests/Instructions/TransferControlTests.cs @@ -0,0 +1,47 @@ +using Apollo.Virtual.AGC.Instructions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AGC.Tests.Instructions +{ + [TestClass] + public class TransferControlTests : BaseTest + { + [TestMethod] + public void TransferControl_Default() + { + // arrange + + // set Z, start execution from here + Memory[0x5] = 0x202; + + // set instruction in memory + Memory[0x202] = TransferControl.Encode(0x400); + + // act + CPU.Execute(); + + // assert + Assert.AreEqual(0x203, Memory[0x2]); // test Q + Assert.AreEqual(0x400, Memory[0x5]); // test Z + } + + [TestMethod] + public void TransferControl_Indirect() + { + // arrange + // TODO: setup A using instruction in future test + Memory[0x0] = 0x201; // set A to address for jump + Memory[0x5] = 0x400; // set Z + + // act + RunInstruction(TransferControl.Encode(0x000)); // Execute Jump + + // run one more cycle + CPU.Execute(); + + // assert + Assert.AreEqual(0x001, Memory[0x2]); // test Q + Assert.AreEqual(0x201, Memory[0x5]); // test Z + } + } +}