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 abstract class ModuleBase | |
| { | |
| public abstract string GetModuleName(); | |
| public abstract string GetModuleFileName(); | |
| public abstract void Load(Machine machine); | |
| public abstract void Unload(Machine machine); | |
| public abstract IEnumerable<string> GetReferencedModules(); | |
| public abstract void Link(Machine machine); | |
| public abstract void Init(Machine machine); | |
| public abstract void Uninit(Machine machine); |
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
| // Recursively call self (ModuleManager) to load each referenced module | |
| foreach (var m in nativeModule.GetReferencedModules()) | |
| { | |
| LoadModule(m); | |
| } | |
| // elsewhere... | |
| // Module16 implements GetReferencedModules by reading the list from the NE file reader | |
| 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
| public override void Load(Machine machine) | |
| { | |
| // Load all segments | |
| for (int i=0; i<_neFile.Segments.Length; i++) | |
| { | |
| // Get the segment | |
| var seg = _neFile.Segments[i]; | |
| // Work out how much memory needed. For the automatic data segments | |
| // add the size of the heap and for programs add on the stack size |
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 Link(Machine machine) | |
| { | |
| for (int i = 0; i < _neFile.Segments.Count; i++) | |
| { | |
| // Get the segment | |
| var seg = segments[i]; | |
| // Get access to the byte array backing it | |
| var data = machine.GlobalHeap.GetBuffer(seg.globalHandle); |
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
| // InternalReference links to another segment in this module | |
| if (reloc.type == RelocationType.InternalReference) | |
| { | |
| var targetSegment = segments[reloc.param1 - 1]; | |
| ApplyRelocations(data, reloc.offset, (uint)(targetSegment.globalHandle << 16 | reloc.param2), additive); | |
| } | |
| // ImportedOrdinal links to an entry point in another module | |
| if (reloc.type == RelocationType.ImportedOrdinal) | |
| { |
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
| void ApplyRelocations(byte[] data, ushort offset, uint value, bool additive) | |
| { | |
| if (additive) | |
| { | |
| data.WriteDWord(offset, (uint)(data.ReadDWord(offset) + value)); | |
| } | |
| else | |
| { | |
| while (offset != 0xFFFF) | |
| { |
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
| foreach (var ep in _neFile.GetAllEntryPoints().Where(x=>(x.flags & Win3muCore.NeFile.EntryPoint.FLAG_EXPORTED)!=0)) | |
| { | |
| // Get the segment | |
| var segment = segments[ep.segmentNumber - 1].globalHandle; | |
| var data = machine.GlobalHeap.GetBuffer(segment); | |
| // Shared DS? | |
| if ((ep.flags & Win3muCore.NeFile.EntryPoint.FLAG_SHAREDDS)!=0) | |
| { | |
| // Insert MOV AX,xxxx instruction |
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 Init(Machine machine) | |
| { | |
| if (IsDll) | |
| { | |
| // Save DS | |
| var saveds = machine.ds; | |
| // Call Library entry point | |
| machine.di = hModule; | |
| machine.ds = DataSegment == null ? (ushort)0 : DataSegment.globalHandle; |
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
| // Module16's GetProcAddress passes through to NeFileReader.GetProcAddress... | |
| public uint GetProcAddress(ushort ordinal) | |
| { | |
| // Look up the entry point | |
| EntryPoint ep; | |
| if (!_entryPoints.TryGetValue(ordinal, out ep)) | |
| return 0; | |
| // Constant? | |
| if (ep.segmentNumber == 0xFE) |
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 class FakeUserDll : ModuleBase | |
| { | |
| public FakeUserDll() | |
| { | |
| } | |
| // A reference back to the machine | |
| Machine _machine; | |
| // Address of the 16-bit MessageBox thunk |