private void Init()
{
memoryManager = new SimpleMemoryManager(this);
PauseEvent = new ManualResetEvent(true);
hooks = hooks ?? new Dictionary<uint, HookDescriptor>();
sync = new Synchronizer();
haltedFinishedEvent = new AutoResetEvent(false);
waitHandles = interruptEvents.Cast<WaitHandle>().Union(new EventWaitHandle[] { PauseEvent, haltedFinishedEvent }).ToArray();
if(currentMappings == null)
{
currentMappings = new List<SegmentMapping>();
}
onTranslationBlockFetch = OnTranslationBlockFetch;
var libraryResource = string.Format("Emul8.translate_{0}-{1}-{2}.so", IntPtr.Size * 8, Architecture, Endianness == Endianess.BigEndian ? "be" : "le");
libraryFile = GetType().Assembly.FromResourceToTemporaryFile(libraryResource);
binder = new NativeBinder(this, libraryFile);
TlibSetTranslationCacheSize(checked((IntPtr)translationCacheSize));
MaximumBlockSize = DefaultMaximumBlockSize;
var result = TlibInit(cpuType);
if(result == -1)
{
throw new InvalidOperationException("Unknown cpu type");
}
if(cpuState != null)
{
var statePtr = TlibExportState();
Marshal.Copy(cpuState, 0, statePtr, cpuState.Length);
AfterLoad(statePtr);
}
HandleRamSetup();
foreach(var hook in hooks)
{
TlibAddBreakpoint(hook.Key);
}
EmulSetCountThreshold(currentCountThreshold);
}