Skip to content

Instantly share code, notes, and snippets.

View toptensoftware's full-sized avatar

Brad Robinson toptensoftware

View GitHub Profile
[EntryPoint(0x0021)]
public bool TextOut(HDC hDC, nint x, nint y, uint pszString, nint cbString)
{
// Get the buffer backing pszString
int offset;
var buf = _machine.GlobalHeap.GetBuffer(pszString, false, out offset);
if (buf == null)
return false;
// Read the string from the buffer, using length param
@toptensoftware
toptensoftware / CPU2.cs
Last active October 23, 2016 11:48
CPU with Debugger
class CPU
{
// Registers
public ushort ax;
public ushort bx;
// etc...
// Busses
public IMemoryBus MemoryBus { get; set; }
public IPortBus PortBus { get; set; }
void RunCode()
{
_cpu = new CPU();
_cpu.MemoryBus = new GlobalHeap();
while (!_theEndOfTime)
{
_cpu.Step();
}
}
@toptensoftware
toptensoftware / IDebugger.cs
Created October 23, 2016 11:54
IDebugger interface
public interface IDebugger
{
bool OnStep();
bool OnSoftwareInterrupt(byte interruptNumber);
}
@toptensoftware
toptensoftware / IDebugger.cs
Created October 23, 2016 11:54
IDebugger interface
public interface IDebugger
{
bool OnStep();
bool OnSoftwareInterrupt(byte interruptNumber);
}
@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
@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 / 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;
public class CodeBreakPoint : BreakPoint
{
public CodeBreakPoint(ushort segment, ushort offset)
{
Segment = segment;
Offset = offset;
}
public ushort Segment;
public ushort Offset;
@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;
}
}