-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Double Precision DAS Instruction
- Loading branch information
Showing
8 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using Apollo.Virtual.AGC.Base; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Instructions | ||
{ | ||
/// <summary> | ||
/// DAS - 0010 00 | ||
/// QuarterCode Instruction | ||
/// | ||
/// A double-precision (DP) add of the A,L register pair to a pair of variables in erasable memory | ||
/// </summary> | ||
class DoubleAddToStorage : IInstruction | ||
{ | ||
public ushort Code | ||
{ | ||
get { return 0x00; } | ||
} | ||
|
||
public Processor CPU { get; set; } | ||
|
||
public void Execute(ushort K) | ||
{ | ||
// find previous address | ||
var K0 = (ushort)(K - 1); | ||
|
||
// read DP values from registers and memroy | ||
var dp1 = new DoublePrecision(CPU.A.Read(), CPU.L.Read()); | ||
var dp2 = new DoublePrecision(CPU.Memory[K0], CPU.Memory[K]); | ||
|
||
// create sum | ||
var sum = dp1 + dp2; | ||
|
||
// store result in memory | ||
CPU.Memory[K0] = sum.MostSignificantWord; | ||
CPU.Memory[K] = sum.LeastSignificantWord; | ||
|
||
// L always cleared to +0 | ||
CPU.L.Write(OnesCompliment.PositiveZero); | ||
|
||
// A set based upon overflow | ||
if(sum.MostSignificantWord.IsPositiveOverflow) | ||
CPU.A.Write(OnesCompliment.PositiveOne); | ||
else if(sum.MostSignificantWord.IsNegativeOverflow) | ||
CPU.A.Write(OnesCompliment.NegativeOne); | ||
else | ||
CPU.A.Write(OnesCompliment.PositiveZero); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using Apollo.Virtual.AGC.Base; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AGC.Tests.Instructions | ||
{ | ||
[TestClass] | ||
public class DoubleAddToStorage : BaseTest | ||
{ | ||
[TestMethod] | ||
public void DoubleAddToStorage_LswValue() | ||
{ | ||
// arrange | ||
Memory[0x0] = 0x0; | ||
Memory[0x1] = OnesCompliment.PositiveOne; | ||
|
||
Memory[0x200] = 0x0; | ||
Memory[0x201] = OnesCompliment.PositiveOne; | ||
|
||
Memory.LoadFixedRom(new ushort[] { | ||
Instruction(0x02, 0x201) | ||
}); | ||
|
||
// act | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(2, Memory[0x201]); | ||
Assert.AreEqual(0, Memory[0x000]); | ||
} | ||
|
||
[TestMethod] | ||
public void DoubleAddToStorage_LswPositiveOverflow() | ||
{ | ||
// arrange | ||
Memory[0x0] = 0x0; | ||
Memory[0x1] = 0x3FFF; | ||
|
||
Memory[0x200] = 0x0; | ||
Memory[0x201] = OnesCompliment.PositiveOne; | ||
|
||
Memory.LoadFixedRom(new ushort[] { | ||
Instruction(0x02, 0x201) | ||
}); | ||
|
||
// act | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(1, Memory[0x200]); | ||
Assert.AreEqual(0, Memory[0x201]); | ||
Assert.AreEqual(0, Memory[0x000]); | ||
} | ||
|
||
[TestMethod] | ||
public void DoubleAddToStorage_MswPositiveOverflow() | ||
{ | ||
// arrange | ||
Memory[0x0] = 0x3FFF; | ||
Memory[0x1] = 0x3FFF; | ||
|
||
Memory[0x200] = 0x0; | ||
Memory[0x201] = OnesCompliment.PositiveOne; | ||
|
||
Memory.LoadFixedRom(new ushort[] { | ||
Instruction(0x02, 0x201) | ||
}); | ||
|
||
// act | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0000, Memory[0x200]); | ||
Assert.AreEqual(0x0000, Memory[0x201]); | ||
Assert.AreEqual(OnesCompliment.PositiveOne, Memory[0x000]); | ||
Assert.AreEqual(OnesCompliment.PositiveZero, Memory[0x001]); | ||
} | ||
} | ||
} |