Skip to content

Commit

Permalink
TransferControl base unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jnosek committed Jul 14, 2020
1 parent b5efd99 commit d73afc9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
7 changes: 4 additions & 3 deletions AGC/Instructions/TransferControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Apollo.Virtual.AGC.Math;

namespace Apollo.Virtual.AGC.Instructions
namespace Apollo.Virtual.AGC.Instructions
{
/// <summary>
/// TC - 0000
Expand All @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions AGC/Memory/MemoryWord.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Apollo.Virtual.AGC.Math;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Apollo.Virtual.AGC.Memory
{
/// <summary>
/// Default 15-bit ones compliment memory word
/// </summary>
[DebuggerDisplay("{Read()}")]
public class MemoryWord : IWord
{
private MemoryBank bank;
Expand Down
47 changes: 47 additions & 0 deletions Tests/AGC.Tests/Instructions/TransferControlTests.cs
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit d73afc9

Please sign in to comment.