-
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.
The Clear And Subtract command
- Loading branch information
Showing
8 changed files
with
98 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Apollo.Virtual.AGC.Base; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Instructions | ||
{ | ||
/// <summary> | ||
/// CS - 0100 | ||
/// | ||
/// The "Clear and Subtract" instruction moves the 1's-complement (i.e., the negative) of a memory location into the accumulator. | ||
/// | ||
/// Also: | ||
/// COM - 0100 0000 0000 0000 | ||
/// The "Complement the Contents of A" bitwise complements the accumulator | ||
/// Assembles as CS A | ||
/// </summary> | ||
class ClearAndSubtract : IInstruction | ||
{ | ||
public ushort Code | ||
{ | ||
get { return 0x4; } | ||
} | ||
|
||
public Processor CPU { get; set; } | ||
|
||
public void Execute(ushort K) | ||
{ | ||
var value = CPU.Memory[K]; | ||
|
||
// write the compliment to the accumulator | ||
CPU.A.Write((ushort)~value); | ||
|
||
// if not the A register, re-write value to K | ||
if (K != CPU.A.Address) | ||
CPU.Memory[K] = value; | ||
} | ||
} | ||
} |
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,48 @@ | ||
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 ClearAndSubtract : BaseTest | ||
{ | ||
[TestMethod] | ||
public void ClearAndSubtractAccumulator() | ||
{ | ||
// arrange | ||
Memory[0x0] = 0x0101; | ||
|
||
Memory.LoadFixedRom(new ushort[] { | ||
0x4000 | ||
}); | ||
|
||
// act | ||
CPU.Execute(); | ||
|
||
// assert | ||
|
||
Assert.AreEqual(0xFEFE, Memory[0x0]); | ||
} | ||
|
||
[TestMethod] | ||
public void ClearAndSubtractMemory() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0xF0F0; | ||
|
||
Memory.LoadFixedRom(new ushort[] { | ||
0x4000 | 0x0200 | ||
}); | ||
|
||
// act | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0F0F, Memory[0x0]); | ||
} | ||
} | ||
} |