public Instruction(VirtualMachine machine) { _machine = machine; Left = new Operand(machine); Right = new Operand(machine); }
public void HandleInterrupt(VirtualMachine machine) { switch (machine.Registers[0]) { case 0: // get status machine.Registers[0] = _sendTimer == 0 ? 1 : 0; break; case 1: // set packet pointer _packetPointer = machine.Registers[1]; break; case 2: // send packet if (_sendTimer != 0) break; _sendTimer = PacketSendCooldown; var data = new byte[PacketSize]; for (var i = 0; i < data.Length; i++) { data[i] = machine.Memory[machine.Registers[1] + i]; } foreach (var c in _parent.State.Entities.Iterate().OfType<Computer>()) { if (c == _parent) continue; c.Broadcast.Enqueue(_parent, data); } break; } }
public static void Main(string[] args) { Window = new RenderWindow(new VideoMode(640, 480), "", Styles.Close); Window.SetFramerateLimit(60); Window.Closed += (sender, eventArgs) => Window.Close(); Window.Resized += (sender, eventArgs) => { var view = new View(); view.Size = new Vector2f(eventArgs.Width, eventArgs.Height); view.Center = view.Size / 2; Window.SetView(view); }; Machine = new VirtualMachine(512 * 1024); var prog = File.ReadAllBytes("bios.bin"); for (var i = 0; i < prog.Length; i++) Machine.Memory[i] = prog[i]; var kbd = new Devices.Keyboard(0x02, Window); Machine.Attach(kbd); var display = new Devices.Display(0x06, Machine, Window); Machine.Attach(display); var hdd = new Devices.HardDrive(0x08, "disk.img"); Machine.Attach(hdd); var running = true; var stepThread = new Thread(() => { while (running) { Machine.Step(); } }); stepThread.Start(); while (Window.IsOpen()) { Window.DispatchEvents(); Window.Clear(); Window.Draw(display); Window.Display(); } running = false; stepThread.Join(); Machine.Dispose(); }
public void HandleInterrupt(VirtualMachine machine) { switch (machine.Registers[0]) { case 0: // enable _enabled = machine.Registers[1] != 0; break; case 1: // set frequency _updateEvery = Program.InstructionsPerSecond / Util.Clamp(machine.Registers[1], 1, 1000); break; } }
public void HandleInterrupt(VirtualMachine machine) { switch (machine.Registers[0]) { case 0: // set thruster speed Thruster = Util.Clamp(machine.Registers[1] / 100f, -1, 1) * -1; break; case 1: // set angular thrusters AngularThruster = Util.Clamp(machine.Registers[1] / 100f, -1, 1); break; } }
public void HandleInterrupt(VirtualMachine machine) { switch (machine.Registers[0]) { case 0: // get coordinates machine.Registers[0] = (int)(_body.Position.X * Program.PixelsPerMeter); machine.Registers[1] = (int)(_body.Position.Y * Program.PixelsPerMeter); break; case 1: // get speed machine.Registers[0] = (int)(_body.LinearVelocity.X * Program.PixelsPerMeter); machine.Registers[1] = (int)(_body.LinearVelocity.Y * Program.PixelsPerMeter); break; case 2: // get angular speed machine.Registers[0] = (int)(_body.AngularVelocity * ((Program.RadarRays / 2) / Math.PI)); break; case 3: // get heading machine.Registers[0] = Util.ToMachineRotation(_body.Rotation - ((float)Math.PI / 2)); break; } }
public Operand(VirtualMachine machine) { _machine = machine; }
public void HandleInterruptRequest(VirtualMachine machine) { }
public void Load(ShipCode code) { Vm = new VirtualMachine(4096); Vm.Attach(new Timer()); Navigation = new Navigation(Body); Vm.Attach(Navigation); Radar = new Radar(this); Vm.Attach(Radar); Engines = new Engines(); Vm.Attach(Engines); Guns = new Guns(); Vm.Attach(Guns); Broadcast = new Broadcast(this); Vm.Attach(Broadcast); Code = code; for (var i = 0; i < Code.Length; i++) { Vm.Memory[i] = Code[i]; } var ptr = 8; var varCount = Vm.Memory.ReadInt(ptr); ptr += sizeof(int); _variables.Clear(); for (var i = 0; i < varCount; i++) { var varAddr = ptr; ptr += sizeof(int); var varType = Vm.Memory.ReadSByte(ptr); ptr += sizeof(sbyte); _variables.Add(new Variable((VariableType)varType, varAddr)); } _programLen = Code.Length; _programOffset = ptr; _programDead = false; for (var i = 0; i < Vm.Registers.Length; i++) { Vm.Registers[i] = 0; } Vm.SP = Vm.Memory.Length; }
public void HandleInterruptRequest(VirtualMachine machine) { var packet = _packetQueue.First(p => p.Delay <= 0); _packetQueue.Remove(packet); machine.Registers[0] = Util.ToMachineRotation(Util.Direction(_parent.Body.Position, packet.SenderPosition)); for (var i = 0; i < packet.Data.Length; i++) { machine.Memory[_packetPointer + i] = packet.Data[i]; } }
public void HandleInterrupt(VirtualMachine machine) { _radarPointer = machine.Registers[0]; }
public void HandleInterruptRequest(VirtualMachine machine) { _timer -= UpdateEvery; RayCast(); for (var i = 0; i < RadarData.Length; i++) { machine.Memory.WriteSByte(_radarPointer + (i * 3) + 0, (sbyte)RadarData[i].Type); machine.Memory.WriteShort(_radarPointer + (i * 3) + 1, RadarData[i].Distance); } }
public void HandleInterrupt(VirtualMachine machine) { Shooting = machine.Registers[0] != 0; }
public void HandleInterruptRequest(VirtualMachine machine) { _timer -= _updateEvery; }