public Broadcast(Computer parent) { _parent = parent; _packetQueue = new List<Packet>(); _packetPointer = 0; _sendTimer = 0; }
public void Enqueue(Computer sender, byte[] data) { if (_packetPointer == 0 || _packetQueue.Count >= 32) return; var distance = Util.Distance(sender.Body.Position, _parent.Body.Position); _packetQueue.Add(new Packet(distance, sender.Body.Position, data)); }
public Radar(Computer parent) { _radarPointer = 0; RadarData = new RadarRay[Program.RadarRays]; _timer = Program.Random.Next(UpdateEvery); // helps with stutter with lots of radars _parent = parent; }
public static int LookupSymbol(Computer computer, string name) { var debugInfo = computer.Code.DebugInfo; if (debugInfo == null) throw new WatchException(string.Format("Undefined: {0}", name)); var symbol = debugInfo.FindSymbol(name); if (!symbol.HasValue) throw new WatchException(string.Format("Undefined: {0}", name)); return symbol.Value.Address; }
private IEnumerable<Line> Disassemble(Computer target, int ip) { var machine = target.Vm; var debugInfo = target.Code.DebugInfo; var instruction = new Instruction(machine); var buffer = new byte[8]; while (true) { var instrAddr = machine.IP; if (instrAddr >= machine.Memory.Length) break; ShipDebug.Line? nextLine = null; if (debugInfo != null) { var symbol = debugInfo.FindSymbol(instrAddr); if (symbol.HasValue && symbol.Value.Address == instrAddr) yield return new Line(instrAddr, string.Format("< {0} >", symbol.Value.Name), false, 1); nextLine = debugInfo.FindLine(instrAddr, 1); } var decodeFailed = false; try { instruction.Decode(); } catch { decodeFailed = true; } if (decodeFailed || !instruction.IsValid || (nextLine.HasValue && instrAddr + instruction.Length > nextLine.Value.Address)) { if (nextLine.HasValue) machine.IP = nextLine.Value.Address; else machine.IP += 4; var read = 0; while (instrAddr <= machine.IP) { if (instrAddr >= machine.Memory.Length) break; buffer[read++] = machine.Memory[instrAddr++]; if (read == buffer.Length || instrAddr == machine.IP) { if (read > 0) { var bufferStr = string.Join(", ", buffer.Take(read).Select(v => string.Format("0x{0:X2}", v))); yield return new Line(instrAddr - read, string.Format(" db {0}", bufferStr), false, 8); } read = 0; } } } else { string sourceLine = null; if (debugInfo != null) { var line = debugInfo.FindLine(instrAddr); if (line.HasValue && line.Value.Address == instrAddr) sourceLine = string.Format("{0}:{1}", line.Value.FileName, line.Value.LineNumber); } var fg = instrAddr == ip ? 4 : 0; var bg = target.HasBreakpoint(instrAddr) ? 15 : 7; yield return new Line(instrAddr, string.Format(" {0}", instruction), true, (byte)fg, (byte)bg, sourceLine); machine.IP += instruction.Length; } } }
public void Update(Computer target) { _scrollbar.Maximum = target.Vm.Memory.Length - (Height * 4); _scrollbar.Value = Util.Clamp(_scrollbar.Value, _scrollbar.Minimum, _scrollbar.Maximum); var debugInfo = target.Code.DebugInfo; var offset = (int)_scrollbar.Value; var originalIp = target.Vm.IP; target.Vm.IP = offset; if (debugInfo != null) { var prevLine = debugInfo.FindLine(offset, -1); if (prevLine.HasValue) target.Vm.IP = prevLine.Value.Address; // TODO: limit how far back this can go } _lines.Clear(); _lines.AddRange(Disassemble(target, originalIp).SkipWhile(l => l.Address < offset).Take((int)Height)); target.Vm.IP = originalIp; }