-
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 ShiftRight and Erasable Bank Register with unit tests
Cleaned up and refactore some code
- Loading branch information
Showing
11 changed files
with
202 additions
and
22 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
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,29 @@ | ||
using Apollo.Virtual.AGC.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Registers | ||
{ | ||
class ErasableBankRegister : MemoryAddress, IWord | ||
{ | ||
public ErasableBankRegister(MemoryBank bank) : | ||
base(0x03, bank) | ||
{ | ||
} | ||
|
||
public ushort Read() | ||
{ | ||
var v = new OnesCompliment(Get()); | ||
v.SignExtend(); | ||
return v; | ||
} | ||
|
||
public void Write(ushort value) | ||
{ | ||
// can only set the 3 bits for the erasable memory bank selection | ||
Set(value & 0x0700); | ||
} | ||
} | ||
} |
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,38 @@ | ||
using Apollo.Virtual.AGC.Core; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Apollo.Virtual.AGC.Registers | ||
{ | ||
class ShiftRightRegister : MemoryAddress, IWord | ||
{ | ||
public ShiftRightRegister(MemoryBank bank) | ||
: base(0x11, bank) | ||
{ | ||
} | ||
|
||
public ushort Read() | ||
{ | ||
var v = new OnesCompliment(Get()); | ||
v.SignExtend(); | ||
return v; | ||
} | ||
|
||
public void Write(ushort value) | ||
{ | ||
// first overflow correct the value | ||
var v = new OnesCompliment(value); | ||
v.OverflowCorrect(); | ||
|
||
value = v; | ||
|
||
// preserve MSB and OR with shifted bits | ||
var bits = (value & 0x4000) | (value >> 1); | ||
|
||
// write the shifted value into memory | ||
Set(bits); | ||
} | ||
} | ||
} |
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; | ||
|
||
namespace AGC.Tests.Registers | ||
{ | ||
[TestClass] | ||
public class ErasableBankRegister : BaseTest | ||
{ | ||
[TestMethod] | ||
public void ErasableBank_SetWithinMask() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0x0200; | ||
|
||
// insert instructions | ||
Memory.LoadFixedRom(new ushort[] { | ||
0x06000 | 0x200, // add to the accumulator | ||
0x05800 | 0x03 // transfer to storage, the EB register | ||
}); | ||
|
||
// act - run the instructions | ||
CPU.Execute(); | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0200, Memory[0x3]); | ||
} | ||
|
||
[TestMethod] | ||
public void ErasableBank_SetOutsideMask() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0x0002; | ||
|
||
// insert instructions | ||
Memory.LoadFixedRom(new ushort[] { | ||
0x06000 | 0x200, // add to the accumulator | ||
0x05800 | 0x03 // transfer to storage, the EB register | ||
}); | ||
|
||
// act - run the instructions | ||
CPU.Execute(); | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0, Memory[0x3]); | ||
} | ||
} | ||
} |
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,75 @@ | ||
using Apollo.Virtual.AGC.Core; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace AGC.Tests.Registers | ||
{ | ||
[TestClass] | ||
public class ShiftRightRegister : BaseTest | ||
{ | ||
[TestMethod] | ||
public void ShiftRight_Default() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0x202; | ||
|
||
// insert instructions | ||
Memory.LoadFixedRom(new ushort[] { | ||
0x06000 | 0x200, // add to the accumulator | ||
0x05800 | 0x011 // transfer to storage, the SR register | ||
}); | ||
|
||
// act - run the instructions | ||
CPU.Execute(); | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0101, Memory[0x11]); | ||
} | ||
|
||
[TestMethod] | ||
public void ShiftRight_ClearLSB() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0x201; | ||
|
||
// insert instructions | ||
Memory.LoadFixedRom(new ushort[] { | ||
0x06000 | 0x200, // add to the accumulator | ||
0x05800 | 0x011 // transfer to storage, the SR register | ||
}); | ||
|
||
// act - run the instructions | ||
CPU.Execute(); | ||
CPU.Execute(); | ||
|
||
// assert | ||
Assert.AreEqual(0x0100, Memory[0x11]); | ||
} | ||
|
||
[TestMethod] | ||
public void ShiftRight_DuplicateMSB() | ||
{ | ||
// arrange | ||
Memory[0x200] = 0xC000; // sign extended 0x4000 value | ||
|
||
// insert instructions | ||
Memory.LoadFixedRom(new ushort[] { | ||
0x06000 | 0x200, // add to the accumulator | ||
0x05800 | 0x011 // transfer to storage, the SR register | ||
}); | ||
|
||
// act - run the instructions | ||
CPU.Execute(); | ||
CPU.Execute(); | ||
|
||
// assert | ||
// sign extended 0x6000 value | ||
Assert.AreEqual(0xE000, Memory[0x11]); | ||
} | ||
} | ||
} |