private void Run() { Stopwatch sw = Stopwatch.StartNew(); while (running) { state = DCPU.step(state); tts++; ticks++; if (state.ticks % 1000 == 0) { for (int i = 0; i < state.peripherals.Count; i++) { state.peripherals[i].updatePeripheral(); } } if (sw.ElapsedMilliseconds - lastMilli >= 1000) { lastElapsed = tts; tts = 0; lastMilli = sw.ElapsedMilliseconds; } while (sw.ElapsedTicks < ticks * 100) { } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space) && !running) { StartDCPU(); } if (Input.GetKeyDown(KeyCode.Return) && !running) { state = DCPU.step(state); if (state.ticks % 1000 == 0) { for (int i = 0; i < state.peripherals.Count; i++) { state.peripherals[i].updatePeripheral(); } } } }
/// <summary> /// Resets the state of the DCPU if a program is loaded. /// </summary> public void Reset() { if (this.IsRunning == true) { throw new InvalidOperationException("Failed to reset the virtual machine. Can not reset the virtual machine while it is running."); } // Create a new instance of the DCPU and load the program into its memory. lock (m_executionLock) { if (m_dcpu != null) { m_dcpu = new DCPU(); Array.Copy(m_program, m_dcpu.Memory, m_program.Length); } } }
/// <summary> /// Loads the given program into the memory of the DCPU. /// </summary> /// <param name="program">The program buffer.</param> public void Load(ushort[] program) { if (program.Length > 0x1000) { throw new ArgumentException("The length of the program exceeds the total amount of available memory."); } lock (m_executionLock) { // Store a copy of the program. m_program = new ushort[program.Length]; Array.Copy(program, m_program, program.Length); // Create a new instance of the DCPU and load the program into its memory. m_dcpu = new DCPU(); Array.Copy(program, m_dcpu.Memory, program.Length); } }
public TomatoDcpu16Adapter(DCPU dcpu16) { _dcpu16 = dcpu16; }