Skip to content

Instantly share code, notes, and snippets.

View toptensoftware's full-sized avatar

Brad Robinson toptensoftware

View GitHub Profile
@toptensoftware
toptensoftware / printableSetList.txt
Created October 13, 2016 04:39
Cantabile's default printable set list template.
<html>
<head>
<title>{Title}</title>
<style>
body { font-family:Arial; margin:20px; font-size:14pt}
</style>
</head>
<body>
<h1>{Title}</h1>
{foreach Sections}
@toptensoftware
toptensoftware / Machine.cs
Last active October 16, 2016 00:39
Machine framework
class Machine : CPU, IBus
{
// Main entry point
public int RunProgram(string programName, string commandTail, int nCmdShow);
// Services
public ModuleManager ModuleManager { get; }
public VariableResolver VariableResolver { get; }
public PathMapper PathMapper { get; }
public DosApi Dos { get; }
@toptensoftware
toptensoftware / DefaultMountPoints.json
Last active October 15, 2016 22:53
Default win3mu mount points
{
"mountPoints":
{
"C:\\WINDOWS":
{
"host": "$(Win3muFolder)\\FILES\\WINDOWS",
"hostWrite": "$(AppData)\\Win3mu\\$(AppName)\\FILES\\WINDOWS",
},
"C:\\$(AppName)":
{
@toptensoftware
toptensoftware / AddMountPoint.json
Created October 15, 2016 23:16
Merging config files
{
"merge:mountPoints":
{
"C:\\MYDATA":
{
"host": "$(MyDocuments)\\MYDATA"
}
}
}
@toptensoftware
toptensoftware / adc.cpp
Created October 15, 2016 23:40
Capturing CPU instruction behaviour
ushort adc16(ushort inFlags, ushort a, ushort b, ushort* outFlags)
{
__asm
{
push word ptr[inFlags]
popf
mov ax, word ptr[a]
adc ax, word ptr[b]
@toptensoftware
toptensoftware / CreatingThunksFromReflection.cs
Created October 19, 2016 03:02
Creating thunks for exported methods
// Create thunks for all exported methods
foreach (var mi in this.GetType().GetMethods())
{
// Check it has an EntryPoint attribute
var ep = mi.GetCustomAttributes<EntryPointAttribute>().FirstOrDefault();
if (ep==null)
continue;
// Create a system thunk for it
var vmptr = _machine.CreateSystemThunk(() => {
@toptensoftware
toptensoftware / ConvertingParametersUsingReflection.cs
Last active October 19, 2016 04:38
Converting Parameters using Reflection
// The parameters that will be passed to the C# code via reflection
List<object> csharpParameters = new List<object();
// Position of next parameter on the VM stack (+4 because the
// caller’s return address is also on the stack)
ushort vmStackPos = _machine.sp + 4;
// Convert all parameters
foreach (var pi in mi.GetParameters())
{
@toptensoftware
toptensoftware / MessageBox2.cs
Created October 19, 2016 03:08
MessageBox using reflection for parameters
// The real API method imported from Windows
[DllImport(“user32.dll”)]
static extern uint MessageBox(IntPtr hWndParent, string msg, string title, uint options);
// Implementation method exported to 16-bit code
[EntryPoint(0x0001)]
public ushort MessageBox(ushort hWndParent, string msg, string title, ushort options)
{
// No more messing around with the VM stack for parameters
// nor with the ax register for the return value. Nice!
@toptensoftware
toptensoftware / nuint.cs
Last active October 19, 2016 03:20
Native types
[MappedType]
public struct nuint
{
public nuint(uint value)
{
this.value = value;
}
public uint value;
@toptensoftware
toptensoftware / MessageBoxFinal.cs
Created October 19, 2016 03:32
MessageBox Final Implementation
[EntryPoint(0x0001)]
[DllImport(“user32.dll”)]
public static extern nuint MessageBox(HWND hWndParent, string msg, string title, nuint options);