// return true if the CPU was reset and the program was loaded public bool ResetCPU(string kernelFilename) { if (CPU != null) { CPU.DebugPause = true; //CPU.Halt(); } if (kernelFilename != null) { LoadedKernel = kernelFilename; } // If the reset vector is not set in Bank 0, but it is set in Bank 18, the copy bank 18 into bank 0. int BasePageAddress = 0x18_0000; if (boardVersion == BoardVersion.RevC) { BasePageAddress = 0x38_0000; } if (LoadedKernel.EndsWith(".fnxml", true, null)) { this.ResetMemory(); FoeniXmlFile fnxml = new FoeniXmlFile(this, Resources); fnxml.Load(LoadedKernel); boardVersion = fnxml.Version; } else { LoadedKernel = HexFile.Load(MemMgr.RAM, LoadedKernel, BasePageAddress, out _, out _); if (LoadedKernel != null) { if (lstFile == null) { lstFile = new ListFile(LoadedKernel); } else { // TODO: This results in lines of code to be shown in incorrect order - Fix ListFile tempList = new ListFile(LoadedKernel); foreach (DebugLine line in tempList.Lines.Values) { if (lstFile.Lines.ContainsKey(line.PC)) { lstFile.Lines.Remove(line.PC); } lstFile.Lines.Add(line.PC, line); for (int i = 1; i < line.commandLength; i++) { if (lstFile.Lines.ContainsKey(line.PC + i)) { lstFile.Lines.Remove(line.PC + i); } } } } } else { return(false); } } // See if lines of code exist in the 0x18_0000 to 0x18_FFFF block for RevB or 0x38_0000 to 0x38_FFFF block for Rev C List <DebugLine> copiedLines = new List <DebugLine>(); if (lstFile.Lines.Count > 0) { foreach (DebugLine line in lstFile.Lines.Values) { if (line != null && line.PC >= BasePageAddress && line.PC < BasePageAddress + 0x1_0000) { DebugLine dl = (DebugLine)line.Clone(); dl.PC -= BasePageAddress; copiedLines.Add(dl); } } } if (copiedLines.Count > 0) { foreach (DebugLine line in copiedLines) { if (lstFile.Lines.ContainsKey(line.PC)) { lstFile.Lines.Remove(line.PC); } lstFile.Lines.Add(line.PC, line); } } CPU.Reset(); return(true); }
public SourcePawnFile(byte[] binary) { BinaryReader reader = new BinaryReader(new MemoryStream(binary)); header_.magic = reader.ReadUInt32(); if (header_.magic != MAGIC) throw new Exception("bad magic - not SourcePawn file"); header_.version = reader.ReadUInt16(); header_.compression = (Compression)reader.ReadByte(); header_.disksize = (int)reader.ReadUInt32(); header_.imagesize = (int)reader.ReadUInt32(); header_.sections = (int)reader.ReadByte(); header_.stringtab = (int)reader.ReadUInt32(); header_.dataoffs = (int)reader.ReadUInt32(); sections_ = new Dictionary<string, Section>(); // There was a brief period of incompatibility, where version == 0x0101 // and the packing changed, at the same time .dbg.ntvarg was introduced. // Once the incompatibility was noted, version was bumped to 0x0102. debugUnpacked_ = (header_.version == 0x0101) && !sections_.ContainsKey(".dbg.natives"); switch (header_.compression) { case Compression.Gzip: { byte[] bits = new byte[header_.imagesize]; for (int i = 0; i < header_.dataoffs; i++) bits[i] = binary[i]; int uncompressedSize = header_.imagesize - header_.dataoffs; int compressedSize = header_.disksize - header_.dataoffs; MemoryStream ms = new MemoryStream(binary, header_.dataoffs + 2, compressedSize - 2); DeflateStream gzip = new DeflateStream(ms, CompressionMode.Decompress); int actualSize = gzip.Read(bits, header_.dataoffs, uncompressedSize); //Debug.Assert(actualSize == uncompressedSize, "uncompressed size mismatch, bad file?"); binary = bits; break; } } // Read sections. for (int i = 0; i < header_.sections; i++) { int nameOffset = (int)reader.ReadUInt32(); int dataoffs = (int)reader.ReadUInt32(); int size = (int)reader.ReadUInt32(); string name = ReadString(binary, header_.stringtab + nameOffset, header_.dataoffs); sections_[name] = new Section(dataoffs, size); } if (sections_.ContainsKey(".code")) { Section sc = sections_[".code"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint codesize = br.ReadUInt32(); byte cellsize = br.ReadByte(); byte codeversion = br.ReadByte(); ushort flags = br.ReadUInt16(); uint main = br.ReadUInt32(); uint codeoffs = br.ReadUInt32(); byte[] codeBytes = Slice(binary, sc.dataoffs + (int)codeoffs, (int)codesize); code_ = new Code(codeBytes, (int)flags, (int)codeversion); } if (sections_.ContainsKey(".data")) { Section sc = sections_[".data"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint datasize = br.ReadUInt32(); uint memsize = br.ReadUInt32(); uint dataoffs = br.ReadUInt32(); byte[] dataBytes = Slice(binary, sc.dataoffs + (int)dataoffs, (int)datasize); data_ = new Data(dataBytes, (int)memsize); } if (sections_.ContainsKey(".publics")) { Section sc = sections_[".publics"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numPublics = sc.size / 8; publics_ = new Public[numPublics]; for (int i = 0; i < numPublics; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); publics_[i] = new Public(name, address); } } if (sections_.ContainsKey(".pubvars")) { Section sc = sections_[".pubvars"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numPubVars = sc.size / 8; pubvars_ = new PubVar[numPubVars]; for (int i = 0; i < numPubVars; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); pubvars_[i] = new PubVar(name, address); } } if (sections_.ContainsKey(".natives")) { Section sc = sections_[".natives"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numNatives = sc.size / 4; natives_ = new Native[numNatives]; for (int i = 0; i < numNatives; i++) { uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); natives_[i] = new Native(name, i); } } if (sections_.ContainsKey(".tags")) { Section sc = sections_[".tags"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numTags = sc.size / 8; tags_ = new Tag[numTags]; for (int i = 0; i < numTags; i++) { uint tag_id = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); tags_[i] = new Tag(name, tag_id); } } if (sections_.ContainsKey(".dbg.info")) { Section sc = sections_[".dbg.info"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugHeader_.numFiles = (int)br.ReadUInt32(); debugHeader_.numLines = (int)br.ReadUInt32(); debugHeader_.numSyms = (int)br.ReadUInt32(); } if (sections_.ContainsKey(".dbg.files") && debugHeader_.numFiles > 0) { Section sc = sections_[".dbg.files"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugFiles_ = new DebugFile[debugHeader_.numFiles]; for (int i = 0; i < debugHeader_.numFiles; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); debugFiles_[i] = new DebugFile(name, nameOffset); } } if (sections_.ContainsKey(".dbg.lines") && debugHeader_.numLines > 0) { Section sc = sections_[".dbg.lines"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugLines_ = new DebugLine[debugHeader_.numLines]; for (int i = 0; i < debugHeader_.numLines; i++) { uint address = br.ReadUInt32(); uint line = br.ReadUInt32(); debugLines_[i] = new DebugLine((int)line, address); } } if (sections_.ContainsKey(".dbg.symbols") && debugHeader_.numSyms > 0) { Section sc = sections_[".dbg.symbols"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); List<Variable> locals = new List<Variable>(); List<Variable> globals = new List<Variable>(); List<Function> functions = new List<Function>(); for (int i = 0; i < debugHeader_.numSyms; i++) { int addr = br.ReadInt32(); short tagid = br.ReadInt16(); uint codestart = br.ReadUInt32(); uint codeend = br.ReadUInt32(); byte ident = br.ReadByte(); Scope vclass = (Scope)br.ReadByte(); ushort dimcount = br.ReadUInt16(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); if (ident == IDENT_FUNCTION) { Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; Function func = new Function((uint)addr, codestart, codeend, name, tag); functions.Add(func); } else { VariableType type = FromIdent(ident); Dimension[] dims = null; if (dimcount > 0) { dims = new Dimension[dimcount]; for (int dim = 0; dim < dimcount; dim++) { short dim_tagid = br.ReadInt16(); Tag dim_tag = dim_tagid >= tags_.Length ? null : tags_[dim_tagid]; uint size = br.ReadUInt32(); dims[dim] = new Dimension(dim_tagid, dim_tag, (int)size); } } Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; Variable var = new Variable(addr, tagid, tag, codestart, codeend, type, vclass, name, dims); if (vclass == Scope.Global) globals.Add(var); else locals.Add(var); } } globals.Sort(delegate(Variable var1, Variable var2) { return var1.address - var2.address; }); functions.Sort(delegate(Function fun1, Function fun2) { return (int)(fun1.address - fun2.address); }); variables_ = locals.ToArray(); globals_ = globals.ToArray(); functions_ = functions.ToArray(); } if (sections_.ContainsKey(".dbg.natives")) { Section sc = sections_[".dbg.natives"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint nentries = br.ReadUInt32(); for (int i = 0; i < (int)nentries; i++) { uint index = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); short tagid = br.ReadInt16(); Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; ushort nargs = br.ReadUInt16(); Argument[] args = new Argument[nargs]; for (ushort arg = 0; arg < nargs; arg++) { byte ident = br.ReadByte(); short arg_tagid = br.ReadInt16(); ushort dimcount = br.ReadUInt16(); uint argNameOffset = br.ReadUInt32(); string argName = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)argNameOffset, header_.dataoffs); Tag argTag = arg_tagid >= tags_.Length ? null : tags_[arg_tagid]; VariableType type = FromIdent(ident); Dimension[] dims = null; if (dimcount > 0) { dims = new Dimension[dimcount]; for (int dim = 0; dim < dimcount; dim++) { short dim_tagid = br.ReadInt16(); Tag dim_tag = dim_tagid >= tags_.Length ? null : tags_[dim_tagid]; uint size = br.ReadUInt32(); dims[dim] = new Dimension(dim_tagid, dim_tag, (int)size); } } args[arg] = new Argument(type, argName, arg_tagid, argTag, dims); } if ((int)index >+ natives_.Length) continue; natives_[index].setDebugInfo(tagid, tag, args); } } // For every function, attempt to build argument information. for (int i = 0; i < functions_.Length; i++) { Function fun = functions_[i]; int argOffset = 12; var args = new List<Argument>(); do { Variable var = lookupVariable(fun.address, argOffset); if (var == null) break; Argument arg = new Argument(var.type, var.name, (int)var.tag.tag_id, var.tag, var.dims); args.Add(arg); argOffset += 4; } while (true); fun.setArguments(args); } }
private void DebugPanel_Paint(object sender, PaintEventArgs e) { bool paint = false; int currentPC = system.CPU.GetLongPC(); //if ((kernel.CPU.DebugPause)) if (true && queue != null) { int queueLength = queue.Count; int painted = 0; int index = 0; // Draw the position box if (position.X > 0 && position.Y > 0) { int row = position.Y / ROW_HEIGHT; int col = 12; e.Graphics.FillRectangle(lightBlueBrush, col, row * ROW_HEIGHT, 7 * 6, 14); } bool offsetPrinted = false; foreach (DebugLine line in queue) { if (line != null) { if (line.PC == currentPC) { paint = true; TopLineIndex = index; if (!offsetPrinted) { if (index > 4) { TopLineIndex -= 5; for (int c = 5; c > 0; c--) { DebugLine q0 = queue[index - c]; if (q0.PC == IRQPC) { e.Graphics.FillRectangle(orangeBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (breakpoints.ContainsKey(q0.PC)) { e.Graphics.FillRectangle(yellowBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } // Check if the memory still matches the opcodes //if (!q0.CheckOpcodes(system.RAM)) if (!q0.CheckOpcodes()) { e.Graphics.FillRectangle(redBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (!q0.isLabel) { e.Graphics.DrawString(q0.ToString(), HeaderTextbox.Font, debugBrush, 2, painted * ROW_HEIGHT); } else { e.Graphics.FillRectangle(debugBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); e.Graphics.DrawString(q0.ToString(), HeaderTextbox.Font, labelBrush, 2, painted * ROW_HEIGHT); } painted++; } } offsetPrinted = true; } e.Graphics.FillRectangle(line.PC == IRQPC ? orangeBrush : lightBlueBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (painted > 26) { paint = false; break; } if (paint) { if (breakpoints.ContainsKey(line.PC)) { e.Graphics.FillRectangle(yellowBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (line.PC == IRQPC) { e.Graphics.FillRectangle(orangeBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } // Check if the memory still matches the opcodes //if (!line.CheckOpcodes(system.RAM)) if (!line.CheckOpcodes()) { e.Graphics.FillRectangle(redBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (line.PC == currentPC || !line.isLabel) { e.Graphics.DrawString(line.ToString(), HeaderTextbox.Font, debugBrush, 2, painted * ROW_HEIGHT); } else { e.Graphics.FillRectangle(debugBrush, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); e.Graphics.DrawString(line.ToString(), HeaderTextbox.Font, labelBrush, 2, painted * ROW_HEIGHT); } painted++; } } index++; } } else { e.Graphics.FillRectangle(lightBlueBrush, 0, 0, this.Width, this.Height); e.Graphics.DrawString("Running code real fast ... no time to write!", HeaderTextbox.Font, debugBrush, 8, DebugPanel.Height / 2); } }
/// <summary> /// Allows physics to draw itself information, only if DebugMode state is activated /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public void Draw() { _camera = CamerasManager.Instance.GetActiveCamera(); graphicsDevice.VertexDeclaration = new VertexDeclaration(graphicsDevice, VertexPositionColor.VertexElements); _visualizationEffect.World = Matrix.Identity; _visualizationEffect.View = _camera.View; _visualizationEffect.Projection = _camera.Projection; DebugRenderable data = Scene.GetDebugRenderable(); _visualizationEffect.Begin(); foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); graphicsDevice.DrawUserPrimitives(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); var vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } graphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); var vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } _visualizationEffect.End(); }
private void Awake() { singleton = this; }
public override void Draw(GameTime gameTime) { this.Device.Clear(Color.LightBlue); this.Device.VertexDeclaration = new VertexDeclaration(this.Device, VertexPositionColor.VertexElements); _visualizationEffect.World = Matrix.Identity; _visualizationEffect.View = this.Camera.View; _visualizationEffect.Projection = this.Camera.Projection; DebugRenderable data = this.Scene.GetDebugRenderable(); _visualizationEffect.Begin(); foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); this.Device.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 2 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 2 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); } this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } this.Device.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } _visualizationEffect.End(); }
IEnumerator BouncingSound( float volume, float distance, Color color, Ray ray) { if (volume <= 0) { yield break; } if ((transform.position - ray.origin).sqrMagnitude > range * range) { yield break; } yield return(new WaitForFixedUpdate()); var hits = Physics.RaycastAll(ray, distance, layerMask); var list = hits.OrderBy(hit => hit.distance); var nextColor = Color.Lerp( color, new Color(color.r, color.g, color.b, 0), 0.5f); var nearest = ray.GetPoint(distance); if (list.Any()) { var hit = list.First(); var renderer = hit.transform.GetComponent <Renderer>(); var tex = renderer.material.mainTexture as Texture2D; if (list.Any()) { nearest = hit.point; } if (tex == null) { (tex = new Texture2D(1, 1)).SetPixel(0, 0, renderer.material.color); } var coords = Vector2.Scale( hit.textureCoord, new Vector2(tex.width, tex.height)); var texel = tex.GetPixel((int)coords.x, (int)coords.y); nextColor = Color.Lerp(nextColor, texel, 0.5f); yield return(StartCoroutine(BouncingSound( volume: CalculateDampening(volume, texel.grayscale), distance: distance, color: nextColor, ray: new Ray( origin: hit.point, direction: Vector3.Reflect( inDirection: ray.direction + ray.origin, inNormal: hit.normal))))); } else { yield return(StartCoroutine(BouncingSound( volume: CalculateDiffusion(volume), distance: distance, color: nextColor, ray: new Ray( origin: ray.GetPoint(distance), direction: ray.direction)))); } //#if _DEBUG DebugLine.DrawLine(ray.origin, nearest, color, nextColor, 10f, 1f); //#endif }
//draw ray functions - http://docs.unity3d.com/Documentation/ScriptReference/Debug.DrawRay.html public static void DrawRay(Vector3 start, Vector3 dir) { DebugLine.DrawLine(start, start + dir, Color.white); }
public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration = 0, float width = 1) { DebugLine.DrawLine(start, start + dir, color, duration, width); }
/// Textbox used for debugging private void DebugLine_Loaded(object sender, RoutedEventArgs e) { DebugLine.Text += "loaded\n"; DebugLine.ScrollToEnd(); }
public void DebugWrite(string text) { DebugLine.Text += text + "\n"; DebugLine.ScrollToEnd(); }
/// <summary> /// Executes next step of 65C816 code, logs dubeugging data /// if debugging check box is set on CPU Window /// </summary> public void ExecuteStep() { StepCounter++; DebugLine line = null; int previousPC = kernel.CPU.PC; if (!kernel.CPU.ExecuteNext()) { int nextPC = kernel.CPU.PC; if (nextPC > MemoryLimit) { UpdateTraceTimer.Enabled = false; kernel.CPU.DebugPause = true; string errorMessage = "PC exceeds memory limit. Calling instruction at address: $" + previousPC.ToString("X6"); if (lastLine.InvokeRequired) { lastLine.Invoke(new lastLineDelegate(ShowLastLine), new object[] { errorMessage }); } else { lastLine.Text = errorMessage; } return; } if (knl_breakpoints.ContainsKey(nextPC) || kernel.CPU.CurrentOpcode.Value == 0 || (BreakOnIRQCheckBox.Checked && (kernel.CPU.Pins.GetInterruptPinActive && InterruptMatchesCheckboxes())) ) { if (kernel.CPU.CurrentOpcode.Value == 0) { if (lastLine.InvokeRequired) { lastLine.Invoke((MethodInvoker) delegate { lastLine.Text = "BRK OpCode read"; }); } else { lastLine.Text = "BRK OpCode read"; } } if (UpdateTraceTimer.Enabled || kernel.CPU.CurrentOpcode.Value == 0) { UpdateTraceTimer.Enabled = false; kernel.CPU.DebugPause = true; //queue.Clear(); } if (kernel.CPU.Pins.GetInterruptPinActive && !kernel.CPU.Flags.IrqDisable) { IRQPC = kernel.CPU.PC; } if (line == null) { line = GetExecutionInstruction(nextPC); if (line == null) { GenerateNextInstruction(nextPC); } } Invoke(new breakpointSetter(BreakpointReached), new object[] { nextPC }); } } // Print the next instruction on lastLine if (!UpdateTraceTimer.Enabled && line == null) { int pc = kernel.CPU.PC; line = GetExecutionInstruction(pc); if (line == null) { GenerateNextInstruction(pc); } } }
private void DebugPanel_MouseMove(object sender, MouseEventArgs e) { if (kernel.CPU.DebugPause) { if (e.X > 2 && e.X < 2 + LABEL_WIDTH) { int top = e.Y / ROW_HEIGHT * ROW_HEIGHT; ActiveLine[0] = 0; DebugPanel.Cursor = Cursors.Default; if ((e.Y / ROW_HEIGHT != position.Y / ROW_HEIGHT || position.Y == -1) && e.Y / ROW_HEIGHT < 28) { position.X = e.X; position.Y = e.Y; AddBPOverlayButton.Top = DebugPanel.Top + top - 1; DeleteBPOverlayButton.Top = DebugPanel.Top + top - 1; InspectOverlayButton.Top = DebugPanel.Top + top - 1; StepOverOverlayButton.Top = DebugPanel.Top + top - 1; LabelOverlayButton.Top = DebugPanel.Top + top - 1; AddBPOverlayButton.Left = 3; DeleteBPOverlayButton.Left = AddBPOverlayButton.Left + AddBPOverlayButton.Width; InspectOverlayButton.Left = DeleteBPOverlayButton.Left + DeleteBPOverlayButton.Width; LabelOverlayButton.Left = InspectOverlayButton.Left + InspectOverlayButton.Width; StepOverOverlayButton.Left = LabelOverlayButton.Left + LabelOverlayButton.Width; AddBPOverlayButton.Visible = true; DeleteBPOverlayButton.Visible = true; InspectOverlayButton.Visible = true; LabelOverlayButton.Visible = true; int row = position.Y / ROW_HEIGHT; // Only show the Step Over button for Jump and Branch commands if (codeList != null && codeList.Count > TopLineIndex + row) { DebugLine line = codeList[TopLineIndex + row]; StepOverOverlayButton.Visible = line.StepOver; } } } else { position.X = -1; position.Y = -1; AddBPOverlayButton.Visible = false; DeleteBPOverlayButton.Visible = false; InspectOverlayButton.Visible = false; StepOverOverlayButton.Visible = false; LabelOverlayButton.Visible = false; ActiveLine[0] = 0; int row = e.Y / ROW_HEIGHT; if (codeList != null && codeList.Count > TopLineIndex + row) { DebugLine line = codeList[TopLineIndex + row]; // try to highlight the word we are over if (line.HasAddress()) { ActiveLine[0] = line.PC; ActiveLine[1] = 174; ActiveLine[2] = line.GetAddressName().Length * 7; DebugPanel.Cursor = Cursors.Hand; } } if (ActiveLine[0] == 0) { DebugPanel.Cursor = Cursors.Default; } } DebugPanel.Refresh(); } }
public LineRenderer(DebugLine line) { this.Lines = new List <DebugLine>(); this.Lines.Add(line); }
public void Awake() { Instance = this; }
//draw line functions - http://docs.unity3d.com/Documentation/ScriptReference/Debug.DrawLine.html public static void DrawLine(Vector3 start, Vector3 end) { DebugLine.DrawLine(start, end, Color.white); }
public void Render(IXNAGame _game) { if (!enabled) { return; } //game.GraphicsDevice.Clear(Color.LightBlue); game.GraphicsDevice.VertexDeclaration = vertexDecl; game.GraphicsDevice.RenderState.AlphaBlendEnable = false; _visualizationEffect.World = Matrix.Identity; _visualizationEffect.View = game.Camera.View; _visualizationEffect.Projection = game.Camera.Projection; DebugRenderable data = physXScene.GetDebugRenderable(); _visualizationEffect.Begin(); foreach (EffectPass pass in _visualizationEffect.CurrentTechnique.Passes) { pass.Begin(); if (data.PointCount > 0) { DebugPoint[] points = data.GetDebugPoints(); game.GraphicsDevice.DrawUserPrimitives <DebugPoint>(PrimitiveType.PointList, points, 0, points.Length); } if (data.LineCount > 0) { DebugLine[] lines = data.GetDebugLines(); VertexPositionColor[] vertices = new VertexPositionColor[data.LineCount * 2 * 2]; for (int x = 0; x < data.LineCount; x++) { DebugLine line = lines[x]; vertices[x * 4 + 0] = new VertexPositionColor(line.Point0, Int32ToColor(line.Color)); vertices[x * 4 + 1] = new VertexPositionColor(line.Point1, Int32ToColor(line.Color)); vertices[x * 4 + 2] = new VertexPositionColor(new Vector3(line.Point0.X, 0, line.Point0.Z), Color.Black); vertices[x * 4 + 3] = new VertexPositionColor(new Vector3(line.Point1.X, 0, line.Point1.Z), Color.Black); } game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, lines.Length * 2); } if (data.TriangleCount > 0) { DebugTriangle[] triangles = data.GetDebugTriangles(); VertexPositionColor[] vertices = new VertexPositionColor[data.TriangleCount * 3]; for (int x = 0; x < data.TriangleCount; x++) { DebugTriangle triangle = triangles[x]; vertices[x * 3 + 0] = new VertexPositionColor(triangle.Point0, Int32ToColor(triangle.Color)); vertices[x * 3 + 1] = new VertexPositionColor(triangle.Point1, Int32ToColor(triangle.Color)); vertices[x * 3 + 2] = new VertexPositionColor(triangle.Point2, Int32ToColor(triangle.Color)); } game.GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.TriangleList, vertices, 0, triangles.Length); } pass.End(); } _visualizationEffect.End(); }
public SourcePawnFile(byte[] binary) { BinaryReader reader = new BinaryReader(new MemoryStream(binary)); header_.magic = reader.ReadUInt32(); if (header_.magic != MAGIC) { throw new Exception("bad magic - not SourcePawn file"); } header_.version = reader.ReadUInt16(); header_.compression = (Compression)reader.ReadByte(); header_.disksize = (int)reader.ReadUInt32(); header_.imagesize = (int)reader.ReadUInt32(); header_.sections = (int)reader.ReadByte(); header_.stringtab = (int)reader.ReadUInt32(); header_.dataoffs = (int)reader.ReadUInt32(); sections_ = new Dictionary <string, Section>(); // There was a brief period of incompatibility, where version == 0x0101 // and the packing changed, at the same time .dbg.ntvarg was introduced. // Once the incompatibility was noted, version was bumped to 0x0102. debugUnpacked_ = (header_.version == 0x0101) && !sections_.ContainsKey(".dbg.natives"); switch (header_.compression) { case Compression.Gzip: { byte[] bits = new byte[header_.imagesize]; for (int i = 0; i < header_.dataoffs; i++) { bits[i] = binary[i]; } int uncompressedSize = header_.imagesize - header_.dataoffs; int compressedSize = header_.disksize - header_.dataoffs; MemoryStream ms = new MemoryStream(binary, header_.dataoffs + 2, compressedSize - 2); DeflateStream gzip = new DeflateStream(ms, CompressionMode.Decompress); int actualSize = gzip.Read(bits, header_.dataoffs, uncompressedSize); //Debug.Assert(actualSize == uncompressedSize, "uncompressed size mismatch, bad file?"); binary = bits; break; } } // Read sections. for (int i = 0; i < header_.sections; i++) { int nameOffset = (int)reader.ReadUInt32(); int dataoffs = (int)reader.ReadUInt32(); int size = (int)reader.ReadUInt32(); string name = ReadString(binary, header_.stringtab + nameOffset, header_.dataoffs); sections_[name] = new Section(dataoffs, size); } if (sections_.ContainsKey(".code")) { Section sc = sections_[".code"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint codesize = br.ReadUInt32(); byte cellsize = br.ReadByte(); byte codeversion = br.ReadByte(); ushort flags = br.ReadUInt16(); uint main = br.ReadUInt32(); uint codeoffs = br.ReadUInt32(); byte[] codeBytes = Slice(binary, sc.dataoffs + (int)codeoffs, (int)codesize); code_ = new Code(codeBytes, (int)flags, (int)codeversion); } if (sections_.ContainsKey(".data")) { Section sc = sections_[".data"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint datasize = br.ReadUInt32(); uint memsize = br.ReadUInt32(); uint dataoffs = br.ReadUInt32(); byte[] dataBytes = Slice(binary, sc.dataoffs + (int)dataoffs, (int)datasize); data_ = new Data(dataBytes, (int)memsize); } if (sections_.ContainsKey(".publics")) { Section sc = sections_[".publics"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numPublics = sc.size / 8; publics_ = new Public[numPublics]; for (int i = 0; i < numPublics; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); publics_[i] = new Public(name, address); } } if (sections_.ContainsKey(".pubvars")) { Section sc = sections_[".pubvars"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numPubVars = sc.size / 8; pubvars_ = new PubVar[numPubVars]; for (int i = 0; i < numPubVars; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); pubvars_[i] = new PubVar(name, address); } } if (sections_.ContainsKey(".natives")) { Section sc = sections_[".natives"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numNatives = sc.size / 4; natives_ = new Native[numNatives]; for (int i = 0; i < numNatives; i++) { uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); natives_[i] = new Native(name, i); } } if (sections_.ContainsKey(".tags")) { Section sc = sections_[".tags"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); int numTags = sc.size / 8; tags_ = new Tag[numTags]; for (int i = 0; i < numTags; i++) { uint tag_id = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".names"].dataoffs + (int)nameOffset, header_.dataoffs); tags_[i] = new Tag(name, tag_id); } } if (sections_.ContainsKey(".dbg.info")) { Section sc = sections_[".dbg.info"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugHeader_.numFiles = (int)br.ReadUInt32(); debugHeader_.numLines = (int)br.ReadUInt32(); debugHeader_.numSyms = (int)br.ReadUInt32(); } if (sections_.ContainsKey(".dbg.files") && debugHeader_.numFiles > 0) { Section sc = sections_[".dbg.files"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugFiles_ = new DebugFile[debugHeader_.numFiles]; for (int i = 0; i < debugHeader_.numFiles; i++) { uint address = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); debugFiles_[i] = new DebugFile(name, nameOffset); } } if (sections_.ContainsKey(".dbg.lines") && debugHeader_.numLines > 0) { Section sc = sections_[".dbg.lines"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); debugLines_ = new DebugLine[debugHeader_.numLines]; for (int i = 0; i < debugHeader_.numLines; i++) { uint address = br.ReadUInt32(); uint line = br.ReadUInt32(); debugLines_[i] = new DebugLine((int)line, address); } } if (sections_.ContainsKey(".dbg.symbols") && debugHeader_.numSyms > 0) { Section sc = sections_[".dbg.symbols"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); List <Variable> locals = new List <Variable>(); List <Variable> globals = new List <Variable>(); List <Function> functions = new List <Function>(); for (int i = 0; i < debugHeader_.numSyms; i++) { int addr = br.ReadInt32(); short tagid = br.ReadInt16(); uint codestart = br.ReadUInt32(); uint codeend = br.ReadUInt32(); byte ident = br.ReadByte(); Scope vclass = (Scope)br.ReadByte(); ushort dimcount = br.ReadUInt16(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); if (ident == IDENT_FUNCTION) { Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; Function func = new Function((uint)addr, codestart, codeend, name, tag); functions.Add(func); } else { VariableType type = FromIdent(ident); Dimension[] dims = null; if (dimcount > 0) { dims = new Dimension[dimcount]; for (int dim = 0; dim < dimcount; dim++) { short dim_tagid = br.ReadInt16(); Tag dim_tag = dim_tagid >= tags_.Length ? null : tags_[dim_tagid]; uint size = br.ReadUInt32(); dims[dim] = new Dimension(dim_tagid, dim_tag, (int)size); } } Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; Variable var = new Variable(addr, tagid, tag, codestart, codeend, type, vclass, name, dims); if (vclass == Scope.Global) { globals.Add(var); } else { locals.Add(var); } } } globals.Sort(delegate(Variable var1, Variable var2) { return(var1.address - var2.address); }); functions.Sort(delegate(Function fun1, Function fun2) { return((int)(fun1.address - fun2.address)); }); variables_ = locals.ToArray(); globals_ = globals.ToArray(); functions_ = functions.ToArray(); } if (sections_.ContainsKey(".dbg.natives")) { Section sc = sections_[".dbg.natives"]; BinaryReader br = new BinaryReader(new MemoryStream(binary, sc.dataoffs, sc.size)); uint nentries = br.ReadUInt32(); for (int i = 0; i < (int)nentries; i++) { uint index = br.ReadUInt32(); uint nameOffset = br.ReadUInt32(); string name = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)nameOffset, header_.dataoffs); short tagid = br.ReadInt16(); Tag tag = tagid >= tags_.Length ? null : tags_[tagid]; ushort nargs = br.ReadUInt16(); Argument[] args = new Argument[nargs]; for (ushort arg = 0; arg < nargs; arg++) { byte ident = br.ReadByte(); short arg_tagid = br.ReadInt16(); ushort dimcount = br.ReadUInt16(); uint argNameOffset = br.ReadUInt32(); string argName = ReadString(binary, sections_[".dbg.strings"].dataoffs + (int)argNameOffset, header_.dataoffs); Tag argTag = arg_tagid >= tags_.Length ? null : tags_[arg_tagid]; VariableType type = FromIdent(ident); Dimension[] dims = null; if (dimcount > 0) { dims = new Dimension[dimcount]; for (int dim = 0; dim < dimcount; dim++) { short dim_tagid = br.ReadInt16(); Tag dim_tag = dim_tagid >= tags_.Length ? null : tags_[dim_tagid]; uint size = br.ReadUInt32(); dims[dim] = new Dimension(dim_tagid, dim_tag, (int)size); } } args[arg] = new Argument(type, argName, arg_tagid, argTag, dims); } if ((int)index > +natives_.Length) { continue; } natives_[index].setDebugInfo(tagid, tag, args); } } // For every function, attempt to build argument information. for (int i = 0; i < functions_.Length; i++) { Function fun = functions_[i]; int argOffset = 12; var args = new List <Argument>(); do { Variable var = lookupVariable(fun.address, argOffset); if (var == null) { break; } Argument arg = new Argument(var.type, var.name, (int)var.tag.tag_id, var.tag, var.dims); args.Add(arg); argOffset += 4; } while (true); fun.setArguments(args); } }
private void DebugPanel_Paint(object sender, PaintEventArgs e) { bool paint = false; int currentPC = kernel.CPU.PC; //if ((kernel.CPU.DebugPause)) if (true && codeList != null) { int queueLength = codeList.Count; int painted = 0; int index = 0; // Draw the position box if (position.X > 0 && position.Y > 0) { int row = position.Y / ROW_HEIGHT; int col = 12; e.Graphics.FillRectangle(Brushes.LightBlue, col, row * ROW_HEIGHT, 7 * 6, 14); } bool offsetPrinted = false; foreach (DebugLine line in codeList) { if (line != null) { if (line.PC == currentPC) { paint = true; TopLineIndex = index; if (!offsetPrinted) { if (index > 4) { TopLineIndex -= 5; for (int c = 5; c > 0; c--) { DebugLine q0 = codeList[index - c]; // Draw the label as a black box with white text if (q0.label != null) { e.Graphics.FillRectangle(Brushes.Blue, 1, painted * ROW_HEIGHT, LABEL_WIDTH + 2, ROW_HEIGHT + 2); e.Graphics.DrawString(q0.label, HeaderTextbox.Font, Brushes.Yellow, 2, painted * ROW_HEIGHT); } if (q0.PC == IRQPC) { e.Graphics.FillRectangle(Brushes.Orange, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } if (knl_breakpoints.ContainsKey(q0.PC)) { e.Graphics.DrawEllipse(Pens.White, LABEL_WIDTH - ROW_HEIGHT - 1, painted * ROW_HEIGHT, ROW_HEIGHT + 1, ROW_HEIGHT + 1); e.Graphics.FillEllipse(Brushes.DarkRed, LABEL_WIDTH - ROW_HEIGHT, painted * ROW_HEIGHT + 1, ROW_HEIGHT, ROW_HEIGHT); } // Check if the memory still matches the opcodes if (!q0.CheckOpcodes(kernel.MemMgr.RAM)) { e.Graphics.FillRectangle(Brushes.Red, LABEL_WIDTH + 3, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } e.Graphics.DrawString(q0.ToString(), HeaderTextbox.Font, Brushes.Black, LABEL_WIDTH + 2, painted * ROW_HEIGHT); if (q0.PC == ActiveLine[0]) { e.Graphics.DrawLine(Pens.Black, LABEL_WIDTH + ActiveLine[1], (painted + 1) * ROW_HEIGHT, LABEL_WIDTH + ActiveLine[1] + ActiveLine[2], (painted + 1) * ROW_HEIGHT); } painted++; } } offsetPrinted = true; } e.Graphics.FillRectangle(line.PC == IRQPC ? Brushes.Orange : Brushes.LightBlue, LABEL_WIDTH + 1, painted * ROW_HEIGHT, DebugPanel.Width, ROW_HEIGHT); } if (painted > 27) { paint = false; break; } if (paint) { if (line.label != null) { e.Graphics.FillRectangle(Brushes.Blue, 1, painted * ROW_HEIGHT, LABEL_WIDTH + 2, ROW_HEIGHT + 2); e.Graphics.DrawString(line.label, HeaderTextbox.Font, Brushes.Yellow, 2, painted * ROW_HEIGHT); } if (knl_breakpoints.ContainsKey(line.PC)) { e.Graphics.DrawEllipse(Pens.White, LABEL_WIDTH - ROW_HEIGHT - 1, painted * ROW_HEIGHT, ROW_HEIGHT + 1, ROW_HEIGHT + 1); e.Graphics.FillEllipse(Brushes.DarkRed, LABEL_WIDTH - ROW_HEIGHT, painted * ROW_HEIGHT + 1, ROW_HEIGHT, ROW_HEIGHT); } if (line.PC == IRQPC) { e.Graphics.FillRectangle(Brushes.Orange, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } // Check if the memory still matches the opcodes if (!line.CheckOpcodes(kernel.MemMgr.RAM)) { e.Graphics.FillRectangle(Brushes.Red, 0, painted * ROW_HEIGHT, this.Width, ROW_HEIGHT); } e.Graphics.DrawString(line.ToString(), HeaderTextbox.Font, Brushes.Black, 102, painted * ROW_HEIGHT); if (line.PC == ActiveLine[0]) { e.Graphics.DrawLine(Pens.Black, LABEL_WIDTH + ActiveLine[1], (painted + 1) * ROW_HEIGHT, LABEL_WIDTH + ActiveLine[1] + ActiveLine[2], (painted + 1) * ROW_HEIGHT); } painted++; } } index++; } } else { e.Graphics.FillRectangle(Brushes.LightBlue, 0, 0, this.Width, this.Height); e.Graphics.DrawString("Running code real fast ... no time to write!", HeaderTextbox.Font, Brushes.Black, 8, DebugPanel.Height / 2); } }
/// <summary> /// If no param for coneArmLength given, what can be seen given sightrange, otherwise what in cone of given arm length /// </summary> /// <param name="hexGrid"></param> /// <param name="coneArmLength"></param> /// <returns></returns> public List <HexPoint> CanSee(int coneArmLength = -1) { if (coneArmLength == -1) { coneArmLength = SightRange; } HexesCanSee = new List <HexPoint>(); //invent hexes for ones that dont exist for the purpose of our calculations var lookDirArms = FoVArms[Rotation]; var lArmR = Location.R + (int)lookDirArms[0].X * coneArmLength; var lArmQ = Location.Q + (int)lookDirArms[0].Y * coneArmLength; var rArmR = Location.R + (int)lookDirArms[1].X * coneArmLength; var rArmQ = Location.Q + (int)lookDirArms[1].Y * coneArmLength; var leftArmCord = new HexPoint(lArmR, lArmQ); var rightArmCord = new HexPoint(rArmR, rArmQ); var shiftRight = (Rotation > 0 && Rotation < 4) ? true : false; var furthestEdge = HexGrid.HexGrid.LineBetweenTwoPoints(leftArmCord, rightArmCord, shiftRight); foreach (var hexPoint in furthestEdge) { var ray = HexGrid.HexGrid.LineBetweenTwoPoints(Location, hexPoint); //:TODO REMOVE after testing var startLinePointHex = ActorHexGrid.HexStorage.First(h => h.Key.Equals(ray[0])).Value; var endLinePoint = ActorHexGrid.HexStorage.First(h => h.Key.Equals(ray[0])).Value; // var debugLine = new DebugLine(); var blocked = false; //should be drawing away from the start point foreach (var rayPoint in ray) { if (!blocked) { if (ActorHexGrid.HexStorage.ContainsKey((rayPoint))) { var hex = ActorHexGrid.HexStorage.First(h => h.Key.Equals(rayPoint)); if (!hex.Value.BlocksVision) { debugLine.DebugStrings[hex.Value.Center] = hex.Key.R + " " + hex.Key.Q; HexesCanSee.Add(hex.Key); endLinePoint = hex.Value; } else { blocked = true; } } else { blocked = true; } } } var debugLineLine = new Line(startLinePointHex.Center.X, startLinePointHex.Center.Y, endLinePoint.Center.X, endLinePoint.Center.Y, 3f, Color.Black); debugLine.Line = debugLineLine; ActorHexGrid.DebugLines.Add(debugLine); } return(HexesCanSee); }