Added Hex Conversions to allow for loading programs into memory from Hex Files.
This commit is contained in:
@@ -4,21 +4,36 @@ namespace CPUSimulation
|
||||
{
|
||||
public class CPU
|
||||
{
|
||||
static string _program = "D8;58;A0;7F;8C;12;D0;A9;A7;8D;11;D0;8D;13;D0;C9;DF;F0;13;C9;9B;F0;03;C8;10;0F;A9;DC;20;EF;FF;A9;8D;20;EF;FF;A0;01;88;30;F6;AD;11;D0;10;FB;AD;10;D0;99;00;02;20;EF;FF;C9;8D;D0;D4;A0;FF;A9;00;AA;0A;85;2B;C8;B9;00;02;C9;8D;F0;D4;C9;AE;90;F4;F0;F0;C9;BA;F0;EB;C9;D2;F0;3B;86;28;86;29;84;2A;B9;00;02;49;B0;C9;0A;90;06;69;88;C9;FA;90;11;0A;0A;0A;0A;A2;04;0A;26;28;26;29;CA;D0;F8;C8;D0;E0;C4;2A;F0;97;24;2B;50;10;A5;28;81;26;E6;26;D0;B5;E6;27;4C;44;FF;6C;24;00;30;2B;A2;02;B5;27;95;25;95;23;CA;D0;F7;D0;14;A9;8D;20;EF;FF;A5;25;20;DC;FF;A5;24;20;DC;FF;A9;BA;20;EF;FF;A9;A0;20;EF;FF;A1;24;20;DC;FF;86;2B;A5;24;C5;28;A5;25;E5;29;B0;C1;E6;24;D0;02;E6;25;A5;24;29;07;10;C8;48;4A;4A;4A;4A;20;E5;FF;68;29;0F;09;B0;C9;BA;90;02;69;06;2C;12;D0;30;FB;8D;12;D0;60;00;00;00;0F;00;FF;00;00";
|
||||
public static int numberOfMemoryBanks = 2;
|
||||
static int memoryBankSize = 1024;
|
||||
static int memoryBankSize = 65536;
|
||||
static MC _memoryController;
|
||||
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
InitilizeMemoryController();
|
||||
|
||||
string[] strings = _program.Split(';');
|
||||
Int16 startAddress = Utils.HexStringToInt16("7F00");
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
Int16 currentAddress = (Int16)(startAddress + i);
|
||||
string byteString = strings[i];
|
||||
if (byteString.Length != 2)
|
||||
{
|
||||
throw new ArgumentException($"Byte string length must be 2. Invalid byte string: {byteString}");
|
||||
}
|
||||
Byte byteToWrite = new Byte(Utils.HexStringToBinaryString(byteString));
|
||||
Word wordToWrite = new Word(new Byte[2] { new Byte("00000000"), byteToWrite });
|
||||
_memoryController.Write(currentAddress, wordToWrite);
|
||||
}
|
||||
_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}");
|
||||
Int16 currentAddress = (Int16)(startAddress + i);
|
||||
string dataRead = Utils.BinaryStringToHexString(_memoryController.Read(currentAddress));
|
||||
Console.WriteLine($"Data read from address {Utils.BinaryStringToHexString(new Address(currentAddress).ToString())}: {dataRead}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user