Files
CPU-Simulation/CPU.cs
T
dbowerman eae5314e3b 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.
2026-06-03 09:54:36 -04:00

60 lines
2.2 KiB
C#

using System;
namespace CPUSimulation
{
public class CPU
{
public static int numberOfMemoryBanks = 2;
static int memoryBankSize = 1024;
static MC _memoryController;
public static void Main(string[] args)
{
InitilizeMemoryController();
_memoryController.Write("0000000000000001","0000000011110000");
_memoryController.Write("0000000000000010","1111000000001111");
for (int i = 0; i < 16; i++)
{
string dataRead = _memoryController.Read((Int16)i);
Console.WriteLine($"Data read from address {new Address((Int16)i).ToString()}: {dataRead}");
}
}
private static void InitilizeMemoryController()
{
_memoryController = new MC(numberOfMemoryBanks, memoryBankSize);
for (int i = 0; i < memoryBankSize; i++)
{
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()}");
}
}
}
}