EightBitNet/MC6809/MC6809.UnitTest/SubTests.cs
Adrian Conlon 72932cf462 Correct a few more style/correctness issues.
Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
2019-05-06 11:02:20 +01:00

130 lines
4.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// <copyright file="SubTests.cs" company="Adrian Conlon">
// Copyright (c) Adrian Conlon. All rights reserved.
// </copyright>
namespace EightBit
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class SubTests
{
private readonly Board board = new Board();
private readonly MC6809 cpu;
public SubTests() => 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();
// Test the SUBA instruction.
// The overflow (V) bit indicates signed twos complement overflow, which
// occurs when the sign bit differs from the carry bit after an arithmetic
// operation.
// A=0x00 - 0xFF becomes 0x01
// positive - negative = positive
[TestMethod]
public void TestImmediateSUBASUBA1()
{
this.board.Poke(0, 0x80);
this.board.Poke(1, 0xff);
this.cpu.CC = (byte)(StatusBits.CF | StatusBits.NF);
this.cpu.A = 0;
this.cpu.Step();
Assert.AreEqual(1, this.cpu.A);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreEqual(0, this.cpu.Overflow);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Negative);
Assert.AreEqual(2, this.cpu.Cycles);
}
// Test the SUBA instruction.
// The overflow (V) bit indicates signed twos complement overflow, which
// occurs when the sign bit differs from the carry bit after an arithmetic
// operation.
// A=0x00 - 0xFF becomes 0x01
// positive - negative = positive
[TestMethod]
public void TestImmediateSUBASUBA2()
{
this.board.Poke(0, 0x80);
this.board.Poke(1, 1);
this.cpu.CC = (byte)(StatusBits.CF | StatusBits.NF);
this.cpu.A = 0;
this.cpu.Step();
Assert.AreEqual(0xff, this.cpu.A);
Assert.AreNotEqual(0, this.cpu.Negative);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Overflow);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreEqual(2, this.cpu.Cycles);
}
// Test the subtraction instruction.
// IMMEDIATE mode: B=0x02 - 0xB3 becomes 0x4F
// positive - negative = positive
[TestMethod]
public void TestImmediateSUBBSUBB1()
{
this.board.Poke(0, 0xc0);
this.board.Poke(1, 0xb3);
this.cpu.CC = 0;
this.cpu.B = 2;
this.cpu.Step();
Assert.AreEqual(0x4f, this.cpu.B);
Assert.AreEqual(0, this.cpu.Negative);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Overflow);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreEqual(2, this.cpu.Cycles);
}
// Test the subtraction instruction.
// IMMEDIATE mode: B=0x02 - 0x81 becomes 0x81
// positive - negative = negative + overflow
[TestMethod]
public void TestImmediateSUBBSUBB2()
{
this.board.Poke(0, 0xc0);
this.board.Poke(1, 0x81);
this.cpu.CC = 0;
this.cpu.B = 2;
this.cpu.Step();
Assert.AreEqual(0x81, this.cpu.B);
Assert.AreNotEqual(0, this.cpu.Negative);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreNotEqual(0, this.cpu.Overflow);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreEqual(2, this.cpu.Cycles);
}
// Example from Programming the 6809.
// 0x03 - 0x21 = 0xE2
// positive - positive = negative
[TestMethod]
public void TestImmediateSUBBSUBBY()
{
this.board.Poke(0, 0xe0);
this.board.Poke(1, 0xa4);
this.board.Poke(0x21, 0x21);
this.cpu.CC = (byte)StatusBits.ZF;
this.cpu.B = 3;
this.cpu.Y.Word = 0x21;
this.cpu.Step();
Assert.AreEqual(0xe2, this.cpu.B);
Assert.AreNotEqual(0, this.cpu.Negative);
Assert.AreEqual(0, this.cpu.Zero);
Assert.AreEqual(0, this.cpu.Overflow);
Assert.AreNotEqual(0, this.cpu.Carry);
Assert.AreEqual(4, this.cpu.Cycles);
}
}
}