Skip to content

Instantly share code, notes, and snippets.

View toptensoftware's full-sized avatar

Brad Robinson toptensoftware

View GitHub Profile
@toptensoftware
toptensoftware / realmode.cs
Last active September 24, 2016 03:05
Real Mode Addressing
public byte ReadByte(ushort seg, ushort offset)
{
return memory[(seg << 4) + offset];
}
@toptensoftware
toptensoftware / protectedmode.cs
Last active September 24, 2016 03:19
Protected Mode Addressing
class Selector
{
public byte[] memory;
}
Selector[] _selectorTable;
public byte ReadByte(ushort seg, ushort offset)
{
var sel = _selectorTable[seg >> 3];
@toptensoftware
toptensoftware / protectedmode2.cs
Created September 24, 2016 03:24
Protected Mode Access Checks
class Selector
{
public byte[] memory;
bool writable;
}
Selector[] _selectorTable;
public void WriteByte(ushort seg, ushort offset, byte value)
{
@toptensoftware
toptensoftware / IBus.cs
Created September 24, 2016 03:27
Sharp86's IBus interface
public interface IBus
{
byte ReadByte(ushort seg, ushort offset);
void WriteByte(ushort seg, ushort offset, byte value);
ushort ReadPortWord(ushort port);
void WritePortWord(ushort port, ushort value);
bool IsExecutableSelector(ushort seg);
}
@toptensoftware
toptensoftware / CpuUnitTest.cs
Created September 25, 2016 02:55
Typical CPU instruction unit test
[TestMethod]
public void Adc_Eb_Gb()
{
WriteByte(0, 100, 40);
FlagC = true;
al = 20;
emit("adc byte [100], al");
run();
Assert.AreEqual(ReadByte(0, 100), 61);
}
@toptensoftware
toptensoftware / RunCpu.cs
Created September 25, 2016 03:01
Typical Sharp86 Usage Pattern
// Create a CPU
_cpu = new CPU();
// Setup the memory bus
_cpu.Bus = _memoryHeap;
// Setup some registers
_cpu.cs = 0x10;
_cpu.ip = 0x100;
_cpu.ax = whatever;
@toptensoftware
toptensoftware / WepUtils.txt
Created October 2, 2016 06:12
Typical NeFile Module Dump
MODULE DUMP: C:\Users\brad\Dropbox\Win16\Games2\WEPUTIL.DLL
App Flags: FullScreeen | WinPMCompat | DLL
Auto Data Segment: 3
CS:IP: 0001:19D2
SS:SP: 0000:0000
Stack Size: 0x0000
Imported Name Table:
1: KERNEL
8: GDI
File Map:
00000000 - 0000003E [003E] MZ Header
0000003E - 00000080 [0042] -
00000080 - 000000C0 [0040] NE Header
000000C0 - 000000D8 [0018] Segment Table
000000D8 - 000001AB [00D3] Resource table
000001AB - 000001AC [0001] -
000001AC - 000001BD [0011] Resident name table
000001BD - 0000029C [00DF] -
0000029C - 000003FB [015F] Non-resident name table
@toptensoftware
toptensoftware / NeFileReader.cs
Last active October 2, 2016 07:29
API to the NeFileReader class
// NeFileReader - opens a 16-bit "NE" file
public class NeFileReader : IDisposable
{
// Constructor, throws exception if error, keeps file open, call IDispose to close
public NeFileReader(string filename);
// Name of currently open file
public string FileName { get; }
// Name of the module extract from name table
@toptensoftware
toptensoftware / RangeAllocator.cs
Last active October 5, 2016 05:56
Win3mu's RangeAllocator
// Manages allocations within an "address space".
public class RangeAllocator<T>
{
// Constructor
public RangeAllocator(int addressSpaceSize);
// Info accessors
public int AddressSpaceSize { get; set; }
public int FreeSpace { get; }
public int EntryCount { get; }