This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Read a byte from the global heap | |
| public byte ReadByte(ushort seg, ushort offset) | |
| { | |
| // Crack the selector | |
| var sel = GetSelector(seg); | |
| try | |
| { | |
| // Read it | |
| return sel.allocation.buffer[((seg >> 3) - sel.selectorIndex) << 16 | offset]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Setup the CPU's instruction pointer | |
| _cpu.cs = selectorFromSegmentIndex(_module.NeHeader.entryPointCS); | |
| _cpu.ip = _module.NeHeader.entryPointIP; | |
| // Run till done | |
| while (!_stopCondition) | |
| { | |
| _cpu.Step() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override void RaiseInterrupt(byte interruptNumber) | |
| { | |
| if (interruptNumber == 0x21 && _cpu.ah == 0x4C) | |
| { | |
| _stopCondition = true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override void RaiseInterrupt(byte interruptNumber) | |
| { | |
| switch (interruptNumber) | |
| { | |
| case 0x21: | |
| // DOS Call | |
| if (_cpu.ah == 0x4C) | |
| _stopCondition = true; | |
| break; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| List<Action> _systemThunkHanders = new List<Action>(); | |
| public uint CreateSystemThunk(Action handler, ushort popStack) | |
| { | |
| // Capture address of this thunk | |
| ushort address = _systemCodeGenPos; | |
| // Store the handler | |
| ushort thunkIndex = (ushort)_systemThunkHanders.Count; | |
| _systemThunkHanders.Add(handler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| uint _sysRetThunk; | |
| void CreateSysRetThunk() | |
| { | |
| // Store address | |
| _sysRetThunk = (uint)(_systemCodeSelector << 16 | _systemCodeGenPos); | |
| // Get memory buffer | |
| byte[] mem = _globalHeap.GetBuffer(_systemCodeSelector); | |
| // INT 81h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void CallVM(uint lpfnProc) | |
| { | |
| // Save the old IP | |
| var oldCS = cs; | |
| var oldIP = ip; | |
| // Setup the new IP | |
| cs = lpfnProc.Hiword(); | |
| ip = lpfnProc.Loword(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Base functionality common to all modules | |
| abstract class ModuleBase | |
| { | |
| } | |
| // Module loaded from 16-bit .exe or .dll | |
| class Module16 : ModuleBase | |
| { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Locate the module (append ".dll" + look in search path) | |
| var locatedModule = LocateModule(fileOrModuleName, parentPath); | |
| if (locatedModule == null) | |
| throw new VirtualException(string.Format("Can't find module '{0}'", fileOrModuleName)); | |
| // Load it | |
| var nativeModule = new Module16(locatedModule); | |
| // elsewhere.... |