private ProcessContextBlock Run(IEnumerable <Instruction> program, Cpu cpu) { IdleProcess.Initialise(cpu); var prog1 = cpu.Load(); var codeSize = cpu.Compile(prog1, program); Console.WriteLine("Code Size: {0} bytes", codeSize); cpu.Run(prog1); var timeout = 1000; while (prog1.IsRunning) { cpu.Tick(); timeout--; if (timeout == 0) { throw new Exception("Timed out while running program"); } } return(prog1); }
public void RunCpu() { var cpu = new Cpu(2048, 256); IdleProcess.Initialise(cpu, IdleProcess.TerminatingIdle); while (cpu.Running) { cpu.Tick(); } }
public void RunRealCpu() { var cpu = new Cpu(2048, 256); IdleProcess.Initialise(cpu, IdleProcess.Instructions); cpu.Tick(); Assert.That(cpu.CurrentProcess, Is.EqualTo(cpu.IdleProcess)); Assert.That(cpu.CurrentProcess.Ip, Is.EqualTo(1)); cpu.Tick(); Assert.That(cpu.CurrentProcess.Registers[0], Is.EqualTo(20)); }
public void RunCpuWithProgram() { var cpu = new Cpu(2048, 256); IdleProcess.Initialise(cpu, IdleProcess.Instructions); var prog1 = cpu.Load(); cpu.Compile(prog1, TestPrograms.ReallySimpleProgram); cpu.Run(prog1); while (prog1.IsRunning) { cpu.Tick(); } Assert.That(prog1.ExitCode, Is.EqualTo(1)); }
public void Sleep() { IdleProcess.Initialise(_cpu); var pA = _cpu.CurrentProcess; Invoke(InstructionsWithControlByte.Sleep, 10); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(_cpu.IdleProcess)); for (int i = 0; i < 10; i++) { _cpu.Tick(); } Assert.That(_cpu.CurrentProcess, Is.SameAs(pA)); }
public void Sleep() { IdleProcess.Initialise(_cpu); var pA = _cpu.CurrentProcess; Instructions.Movi(_cpu, Register.A, 10); Instructions.Sleep(_cpu, Register.A); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(_cpu.IdleProcess)); for (int i = 0; i < 10; i++) { _cpu.Tick(); } Assert.That(_cpu.CurrentProcess, Is.SameAs(pA)); }
public void Printc() { IdleProcess.Initialise(_cpu); var pA = _cpu.CurrentProcess; var printStack = new Stack <uint>(); _cpu.OutputMethod = printStack.Push; Invoke(InstructionsWithControlByte.Mov, Register.A, (uint)DeviceId.Terminal); Invoke(InstructionsWithControlByte.Output, Register.A, 10); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(_cpu.IdleProcess)); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(pA)); Assert.That(printStack.Peek(), Is.EqualTo(10)); }
public void Input() { IdleProcess.Initialise(_cpu); var pA = _cpu.CurrentProcess; Invoke(InstructionsWithControlByte.Input, Register.C, (uint )DeviceId.Terminal); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(_cpu.IdleProcess)); _cpu.InputDevice.Push(99); for (int i = 0; i < 2; i++) { _cpu.Tick(); } Assert.That(_cpu.CurrentProcess, Is.SameAs(pA)); Assert.That(C, Is.EqualTo(99)); }
public void Input() { IdleProcess.Initialise(_cpu); var pA = _cpu.CurrentProcess; Instructions.Input(_cpu, Register.C); _cpu.Tick(); Assert.That(_cpu.CurrentProcess, Is.SameAs(_cpu.IdleProcess)); _cpu.InputDevice.Push(99); for (int i = 0; i < 2; i++) { _cpu.Tick(); } Assert.That(_cpu.CurrentProcess, Is.SameAs(pA)); Assert.That(C, Is.EqualTo(99)); }
public void ProgramSignals() { var cpu = new Cpu(2048, 256); IdleProcess.Initialise(cpu, IdleProcess.Instructions); var prog1 = cpu.Load(); var prog2 = cpu.Load(); cpu.Compile(prog1, TestPrograms.P1); cpu.Compile(prog2, TestPrograms.P2); cpu.Run(prog1); cpu.Run(prog2); while (prog1.IsRunning || prog2.IsRunning) { cpu.Tick(); } Assert.That(prog1.ExitCode, Is.EqualTo(1)); Assert.That(prog2.ExitCode, Is.EqualTo(1)); }