summaryrefslogtreecommitdiff
path: root/Q1.tests/Core
diff options
context:
space:
mode:
authorMelodi <62381002+Melodi17@users.noreply.github.com>2026-03-30 16:28:30 +1000
committerMelodi <62381002+Melodi17@users.noreply.github.com>2026-03-30 16:28:30 +1000
commit512a5f0efeea46994d01124b409ef51f9b9177a0 (patch)
treecf759c919746afc734246410f08fa91e8faed99a /Q1.tests/Core
parent571e44a12d2a52e92c1165ec294469d3d384faef (diff)
add: Bit shifting data tests
Diffstat (limited to 'Q1.tests/Core')
-rw-r--r--Q1.tests/Core/Instructions/DataInstructionTests.cs158
1 files changed, 158 insertions, 0 deletions
diff --git a/Q1.tests/Core/Instructions/DataInstructionTests.cs b/Q1.tests/Core/Instructions/DataInstructionTests.cs
index 08bc8cc..876d6cd 100644
--- a/Q1.tests/Core/Instructions/DataInstructionTests.cs
+++ b/Q1.tests/Core/Instructions/DataInstructionTests.cs
@@ -1,6 +1,7 @@
namespace Q1.tests.Core.Instructions;
using core.Arch;
+using core.Arch.Constants;
using core.Arch.Lookups;
using core.Components;
@@ -161,6 +162,163 @@ public class DataInstructionTests : InstructionTestBase
u16 expected = (u16) (value16_1 ^ value16_2);
Assert.That(chip.Dx, Is.EqualTo(expected));
}
+
+ [Test]
+ public void ShiftLeftInPlaceDxInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+
+ var chip = this.CreateChip();
+ chip.Dx = value16;
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHPL(DX)"),
+ 0,
+ 0,
+ true);
+ chip.Bus.WriteWord(chip.Pc, instruction);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) ((value16 << 1) | (value16 >> 15));
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
+
+ [Test]
+ public void ShiftLeftInPlaceInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+
+ var chip = this.CreateChip();
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHPL"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ 0,
+ true);
+
+ chip.Bus.WriteWord(chip.Pc, instruction);
+ chip.Bus.WriteWord((u16) (chip.Pc + 2), value16);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) ((value16 << 1) | (value16 >> 15));
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
+ [Test]
+ public void ShiftLeftInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+ u16 shiftAmount = 3;
+
+ var chip = this.CreateChip();
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHL"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ true);
+
+ chip.Bus.WriteWord(chip.Pc, instruction);
+ chip.Bus.WriteWord((u16) (chip.Pc + 2), value16);
+ chip.Bus.WriteWord((u16) (chip.Pc + 4), shiftAmount);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) (value16 << shiftAmount);
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
+ [Test]
+ public void ShiftRightInPlaceDxInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+
+ var chip = this.CreateChip();
+ chip.Dx = value16;
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHPR(DX)"),
+ 0,
+ 0,
+ true);
+
+ chip.Bus.WriteWord(chip.Pc, instruction);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) (value16 >> 1);
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
+
+ [Test]
+ public void ShiftRightInPlaceInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+
+ var chip = this.CreateChip();
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHPL"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ 0,
+ true);
+
+ chip.Bus.WriteWord(chip.Pc, instruction);
+ chip.Bus.WriteWord((u16) (chip.Pc + 2), value16);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) ((value16 >> 1) | (value16 << 15));
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
+
+ [Test]
+ public void ShiftRightInstruction_ShouldCorrectlyShiftBits()
+ {
+ // Arrange
+ u16 value16 = 0b1010101010101010;
+ u16 shiftAmount = 3;
+
+ var chip = this.CreateChip();
+
+ var instruction = InstructionEncoding
+ .Encode(
+ InstructionSet.GetOpcode("SHR"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ AddressingModes.GetAddressingMode("Immediate"),
+ true);
+
+ chip.Bus.WriteWord(chip.Pc, instruction);
+ chip.Bus.WriteWord((u16) (chip.Pc + 2), value16);
+ chip.Bus.WriteWord((u16) (chip.Pc + 4), shiftAmount);
+
+ // Act
+ chip.Clock();
+
+ // Assert
+ u16 expected = (u16) (value16 >> shiftAmount);
+ Assert.That(chip.Dx, Is.EqualTo(expected));
+ }
} \ No newline at end of file