Add more indexed addressing mode tests to the MC6809 core.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2019-06-09 10:37:46 +01:00
parent ef148528b1
commit c11143f22d
3 changed files with 168 additions and 1 deletions

View File

@ -41,7 +41,7 @@ namespace EightBit
// Indirect mode: CMPA ,Y+ (CMP1)
[TestMethod]
public void TestCMP1()
public void TestCMP1_indexed_y_plus()
{
this.board.Poke(0, 0xa1);
this.board.Poke(1, 0xa0);
@ -62,6 +62,75 @@ namespace EightBit
Assert.AreEqual(6, this.cpu.Cycles);
}
// Indirect mode: CMPA ,Y++ (CMP1)
[TestMethod]
public void TestCMP1_indexed_y_plusplus()
{
this.board.Poke(0, 0xa1);
this.board.Poke(1, 0xa1);
this.board.Poke(0x205, 0xff);
this.cpu.CC = 0;
this.cpu.A = 0xff;
this.cpu.B = 0;
this.cpu.X.Word = 0;
this.cpu.Y.Word = 0x205;
this.cpu.U.Word = 0;
this.cpu.Step();
Assert.AreEqual(0xff, this.cpu.A);
Assert.AreEqual(0, this.cpu.B);
Assert.AreEqual(0, this.cpu.X.Word);
Assert.AreEqual(0x207, this.cpu.Y.Word);
Assert.AreEqual(0, this.cpu.U.Word);
Assert.AreNotEqual(0, this.cpu.Zero);
Assert.AreEqual(7, this.cpu.Cycles);
}
// Indirect mode: CMPA ,-Y (CMP1)
[TestMethod]
public void TestCMP1_indexed_minus_y()
{
this.board.Poke(0, 0xa1);
this.board.Poke(1, 0xa2);
this.board.Poke(0x204, 0xff);
this.cpu.CC = 0;
this.cpu.A = 0xff;
this.cpu.B = 0;
this.cpu.X.Word = 0;
this.cpu.Y.Word = 0x205;
this.cpu.U.Word = 0;
this.cpu.Step();
Assert.AreEqual(0xff, this.cpu.A);
Assert.AreEqual(0, this.cpu.B);
Assert.AreEqual(0, this.cpu.X.Word);
Assert.AreEqual(0x204, this.cpu.Y.Word);
Assert.AreEqual(0, this.cpu.U.Word);
Assert.AreNotEqual(0, this.cpu.Zero);
Assert.AreEqual(6, this.cpu.Cycles);
}
// Indirect mode: CMPA ,Y++ (CMP1)
[TestMethod]
public void TestCMP1_indexed_minusminus_y()
{
this.board.Poke(0, 0xa1);
this.board.Poke(1, 0xa3);
this.board.Poke(0x203, 0xff);
this.cpu.CC = 0;
this.cpu.A = 0xff;
this.cpu.B = 0;
this.cpu.X.Word = 0;
this.cpu.Y.Word = 0x205;
this.cpu.U.Word = 0;
this.cpu.Step();
Assert.AreEqual(0xff, this.cpu.A);
Assert.AreEqual(0, this.cpu.B);
Assert.AreEqual(0, this.cpu.X.Word);
Assert.AreEqual(0x203, this.cpu.Y.Word);
Assert.AreEqual(0, this.cpu.U.Word);
Assert.AreNotEqual(0, this.cpu.Zero);
Assert.AreEqual(7, this.cpu.Cycles);
}
// B = 0xA0, CMPB with 0xA0
[TestMethod]
public void TestCMP2()

View File

@ -0,0 +1,97 @@
// <copyright file="LeaTests.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class LeaTests
{
private readonly Board board = new Board();
private readonly MC6809 cpu;
public LeaTests() => this.cpu = this.board.CPU;
[TestInitialize]
public void Initialise()
{
this.board.RaisePOWER();
this.cpu.Step(); // Step over the reset
}
[TestCleanup]
public void Cleanup() => this.board.LowerPOWER();
[TestMethod]
public void TestLEA_one()
{
ushort location = 0x1e20;
//// LEAX n,PCR (16-bit)
this.board.Poke(location, 0x30);
this.board.Poke((ushort)(location + 1), 0x8d);
this.cpu.PokeWord((ushort)(location + 2), 0xfe49);
this.cpu.PC.Word = location;
this.cpu.Step();
var offset = 0x10000 - 0xfe49;
Assert.AreEqual(location + 4 - offset, this.cpu.X.Word);
Assert.AreEqual(location + 4, this.cpu.PC.Word);
}
[TestMethod]
public void TestLEA_two()
{
ushort location = 0x846;
//// LEAX n,PCR (8-bit)
this.board.Poke(location, 0x30);
this.board.Poke((ushort)(location + 1), 0x8c);
this.board.Poke((ushort)(location + 2), 0xf1);
this.cpu.PC.Word = location;
this.cpu.Step();
var offset = 0x100 - 0xf1;
Assert.AreEqual(location + 3 - offset, this.cpu.X.Word);
Assert.AreEqual(location + 3, this.cpu.PC.Word);
}
[TestMethod]
public void TestLEA_three()
{
this.board.Poke(0, 0x30);
this.board.Poke(1, 0xab);
this.cpu.CC = 0;
this.cpu.X.Word = 0xabcd;
this.cpu.Y.Word = 0x804f;
this.cpu.A = 0x80;
this.cpu.B = 0x01;
this.cpu.Step();
Assert.AreEqual(0x50, this.cpu.X.Word);
Assert.AreEqual(0, this.cpu.Zero);
}
[TestMethod]
public void TestLEA_four()
{
this.board.Poke(0, 0x30);
this.board.Poke(1, 0xab);
this.cpu.CC = 0x28;
this.cpu.X.Word = 0xefa;
this.cpu.Y.Word = 0xef8;
this.cpu.A = 0xff;
this.cpu.B = 0x82;
this.cpu.Step();
Assert.AreEqual(0xe7a, this.cpu.X.Word);
Assert.AreEqual(0, this.cpu.Zero);
}
}
}

View File

@ -84,6 +84,7 @@
<Compile Include="LsrTests.cs" />
<Compile Include="RorTests.cs" />
<Compile Include="ComTests.cs" />
<Compile Include="LeaTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\EightBit\EightBit.csproj">