using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Contralto.CPU { struct RomFile { public RomFile(string filename, ushort addr, int bitPosition) { Filename = filename; StartingAddress = addr; BitPosition = bitPosition; } public string Filename; public ushort StartingAddress; public int BitPosition; } static class UCodeMemory { static UCodeMemory() { Init(); } private static void Init() { _uCodeRam = new UInt32[1024]; LoadMicrocode(_uCodeRoms); _decodeCache = new MicroInstruction[2048]; CacheMicrocodeDecode(); } public static UInt32[] UCodeROM { get { return _uCodeRom; } } public static UInt32[] UCodeRAM { get { return _uCodeRam; } } public static MicroInstruction[] DecodeCache { get { return _decodeCache; } } private static void LoadMicrocode(RomFile[] romInfo) { _uCodeRom = new UInt32[2048]; foreach(RomFile file in romInfo) { // // Each file contains 1024 bytes, each byte containing one nybble in the low 4 bits. // using(FileStream fs = new FileStream(Path.Combine("ROM", file.Filename), FileMode.Open, FileAccess.Read)) { int length = (int)fs.Length; if (length != 1024) { throw new InvalidOperationException("ROM file should be 1024 bytes in length"); } byte[] data = new byte[fs.Length]; fs.Read(data, 0, (int)fs.Length); // OR in the data for(int i=0;i