Skip to content

Instantly share code, notes, and snippets.

View toptensoftware's full-sized avatar

Brad Robinson toptensoftware

View GitHub Profile
public class Tokenizer
{
public Tokenizer(TextReader reader);
// The current token
public Token Token { get; }
// The value of the number of Token.Number
public double Number { get; }
public enum Token
{
EOF,
Add,
Subtract,
Number,
}
@toptensoftware
toptensoftware / DebuggerBreak.cs
Created October 23, 2016 12:52
Debugger Break Method
// Force break in the debugger on the next instruction
public void Break()
{
_break = true;
}
public class StepOutBreakPoint : BreakPoint
{
public StepOutBreakPoint(CPU cpu)
{
// Store the current stack pointer
_ssBreakOnReturn = cpu.ss;
_spBreakOnReturn = cpu.sp;
}
ushort _ssBreakOnReturn = 0;
@toptensoftware
toptensoftware / StepAndStepOver.cs
Created October 23, 2016 12:19
Sharp86 Step and Step Over
// Single Step
void SingleStep()
{
_break = true;
}
// Step Over
public void StepOver()
{
// Check if the current instruction is a call instruction
@toptensoftware
toptensoftware / DebuggerOnStep.cs
Created October 23, 2016 12:15
Debugger OnStep
void IDebugger.OnStep()
{
// Test all break points
for (int i=0; i<_allBreakPoints.Count; i++)
{
if (bp.Enabled && bp.ShouldBreak(this))
{
_break = true;
}
}
public class CodeBreakPoint : BreakPoint
{
public CodeBreakPoint(ushort segment, ushort offset)
{
Segment = segment;
Offset = offset;
}
public ushort Segment;
public ushort Offset;
@toptensoftware
toptensoftware / CodeBreakPoint.cs
Created October 23, 2016 12:09
Sharp86 Code Break Point
public class CodeBreakPoint : BreakPoint
{
public CodeBreakPoint(ushort segment, ushort offset)
{
Segment = segment;
Offset = offset;
}
public ushort Segment;
public ushort Offset;
@toptensoftware
toptensoftware / BreakPoint.cs
Last active October 23, 2016 12:08
Sharp86 Break Point class
public abstract class BreakPoint
{
// Check if this break point wants the debugger to stop
public abstract bool ShouldBreak(DebuggerCore debugger);
[Json("number")]
public int Number { get; set; }
[Json("enabled")]
public bool Enabled { get; set; }
@toptensoftware
toptensoftware / Disassembler.cs
Created October 23, 2016 12:03
Sharp86 Disassembler
public class Disassembler
{
// Machine code read from here
public IMemoryBus MemoryBus { get; set; }
// Using this address
public ushort cs { get; set; }
public ushort ip { get; set; }
// Read disassembled instruction here