public VirtualCPU(byte arch, bool initCache = false, int CacheSize = 0) { this.arch = arch; isCacheInit = initCache; if (isCacheInit && CacheSize > 0) { Cache = new VirtualMemory(); } else { isCacheInit = false; } return; }
public void ReadData() { try { if (FileName != null && Data == null) { if (!File.Exists(FileName)) { throw new FileNotFoundException(); } Data = File.ReadAllBytes(FileName); } if (Type == 0) { Type = Data[0]; } InstructionSet = Data[1]; List <int> tempRam = new List <int>(); int i; for (i = 2; i < Data.Length; i += 4) { List <byte> temp = new List <byte>(); if (Data[i] == 0xFF && Data[i + 1] == 0xFA && Data[i + 2] == 0xFF && Data[i + 3] == 0xFA && Data[i + 4] == 0xFB) { i += 5; break; } for (int c = 0; c < 4; c++) { temp.Add(Data[i + c]); } int d = BitConverter.ToInt32(temp.ToArray(), 0); tempRam.Add(d); } if (Type != 1 && Type != 2 && Type != 3) { throw new NotImplementedException(); } List <byte> tempOP = new List <byte>(); for (; i < Data.Length; i++) { tempOP.Add(Data[i]); } if (Type == 1) { op8 = tempOP.ToArray(); } else if (Type == 2) { List <short> temp16OP = new List <short>(); for (i = 0; i < tempOP.Count; i++) { List <byte> toAdd = new List <byte>(); for (int c = 0; c < 2; c++) { toAdd.Add(tempOP[c + i]); } temp16OP.Add(BitConverter.ToInt16(toAdd.ToArray(), 0)); } op16 = temp16OP.ToArray(); } else if (Type == 3) { List <int> temp32OP = new List <int>(); for (i = 0; i < tempOP.Count; i += 4) { List <byte> toAdd = new List <byte>(); for (int c = 0; c < 4; c++) { toAdd.Add(tempOP[c + i]); } toAdd.Reverse(); temp32OP.Add(BitConverter.ToInt32(toAdd.ToArray(), 0)); } op32 = temp32OP.ToArray(); } Data = null; Memory = new VirtualMemory(); Memory.AddArray(tempRam); if (usingInstructionSet == null) { usingInstructionSet = Types.Sets[InstructionSet]; } } catch (Exception ex) { Sys.Console.WriteLine($"Error reading executable data: {ex.Message}"); } }