public void Run(string programpath) { var display = new ConsoleDisplay(); var keyboard = new ConsoleKeyboard(); memory = new Memory(); cpu = new CPU(memory, display, keyboard); disassembler = new Disassembler(); // Load ROM var romfile = File.OpenRead("ROM.bin"); var rom = new byte[512]; romfile.Read(rom, 0, 512); romfile.Close(); memory.InitializeROM(rom); // Load Program var programfile = File.OpenRead(programpath); var program = new byte[3584]; programfile.Read(program, 0, 3584); memory.LoadProgram(program); // Start clock Stopwatch sw = new Stopwatch(); var cpuspeed = 6 * Stopwatch.Frequency / 1000; while (true) { var debug = keyboard.CheckKeys(); if (debug) { StartDebugging(); debug = false; continue; } if (!sw.IsRunning || sw.ElapsedTicks > cpuspeed) { cpu.Clock(); sw.Restart(); } } }
public void Run(string programpath) { var display = new ConsoleDisplay(); var keyboard = new ConsoleKeyboard(); memory = new Memory(); cpu = new CPU(memory, display, keyboard); disassembler = new Disassembler(); // Load ROM var romfile = File.OpenRead("ROM.bin"); var rom = new byte[512]; romfile.Read(rom, 0, 512); romfile.Close(); memory.InitializeROM(rom); // Load Program var programfile = File.OpenRead(programpath); var program = new byte[3584]; programfile.Read(program, 0, 3584); memory.LoadProgram(program); // Start clock Stopwatch sw = new Stopwatch(); var cpuspeed = 6 * Stopwatch.Frequency / 1000; while (true){ var debug = keyboard.CheckKeys(); if (debug){ StartDebugging(); debug = false; continue; } if(!sw.IsRunning || sw.ElapsedTicks > cpuspeed) { cpu.Clock(); sw.Restart(); } } }