added a new ToString method to Word, DWord, and QWord classes.

The ToString method will concatenate the string representations of the high and low words (or dwords) to create a single string representation of the entire word.
This can be used to more easily write and read the value from the MC and CU classes.
This commit is contained in:
2026-06-03 09:54:36 -04:00
parent faa7801376
commit eae5314e3b
15 changed files with 132 additions and 18 deletions
+24 -5
View File
@@ -4,7 +4,7 @@ namespace CPUSimulation
{
public class CPU
{
static int numberOfMemoryBanks = 4;
public static int numberOfMemoryBanks = 2;
static int memoryBankSize = 1024;
static MC _memoryController;
@@ -17,8 +17,8 @@ namespace CPUSimulation
_memoryController.Write("0000000000000010","1111000000001111");
for (int i = 0; i < 16; i++)
{
Word dataRead = _memoryController.Read((Int16)i);
Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead.ToString()}");
string dataRead = _memoryController.Read((Int16)i);
Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead}");
}
}
@@ -27,8 +27,27 @@ namespace CPUSimulation
_memoryController = new MC(numberOfMemoryBanks, memoryBankSize);
for (int i = 0; i < memoryBankSize; i++)
{
Word dataToWrite = Utils.GenerateRandomWord(numberOfMemoryBanks);
_memoryController.Write((Int16)i, dataToWrite);
if (numberOfMemoryBanks == 2)
{
Word dataToWrite = Utils.GenerateRandomWord(numberOfMemoryBanks);
_memoryController.Write(new Address((Int16)i).ToString(), dataToWrite.ToString());
}
else if (numberOfMemoryBanks == 4)
{
DWord dataToWrite = new DWord(Utils.GenerateRandomWord(2), Utils.GenerateRandomWord(2));
_memoryController.Write(new Address((Int16)i).ToString(), dataToWrite.ToString());
}
else if (numberOfMemoryBanks == 8)
{
QWord dataToWrite = new QWord(new DWord(Utils.GenerateRandomWord(2), Utils.GenerateRandomWord(2)), new DWord(Utils.GenerateRandomWord(2), Utils.GenerateRandomWord(2)));
_memoryController.Write(new Address((Int16)i).ToString(), dataToWrite.ToString());
}
else
{
throw new ArgumentException($"Number of memory banks must be between 1 and 8 (inclusive).");
}
//Word dataRead = _memoryController.Read((Int16)i);
//Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead.ToString()}");
}