Ejemplo n.º 1
0
        public Machine()
        {
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += UnhandledException;
            }
            else
            {
                enableDebugger = true;
                logExecution   = true;
            }

            _pathMapper        = new PathMapper(this);
            _globalHeap        = new GlobalHeap(this);
            _stringHeap        = new StringHeap(this);
            _moduleManager     = new ModuleManager(this);
            _messaging         = new Messaging(this);
            _variableResolver  = new VariableResolver();
            _expressionContext = new ExpressionContext(this);
            _symbolResolver    = new SymbolResolver(this);
            _stackWalker       = new StackWalker(this);
            _expressionContext.PushSymbolScope(_symbolResolver);

            this.MemoryBus = _globalHeap;

            RegisterVariables();

            // Create system heaps
            _systemCodeSelector = _globalHeap.Alloc("System Thunks", 0, 0x10000);
            _globalHeap.SetSelectorAttributes(_systemCodeSelector, true, true);
            _systemDataHeap = _globalHeap.CreateLocalHeap("System Local Heap", 0);
            _globalHeap.SetSelectorAttributes(_systemDataHeap.GlobalHandle, false, false);

            // Initialise the system return thunk
            CreateSysRetThunk();

            // Creae DOS Api handler
            _dos = new DosApi(this, this);

            // Load standard modules
            _kernel = _moduleManager.LoadModule(new Kernel()) as Kernel;
            _user   = _moduleManager.LoadModule(new User()) as User;
            _moduleManager.LoadModule(new Gdi());
            _moduleManager.LoadModule(new MMSystem());
            _moduleManager.LoadModule(new Keyboard());
//            _moduleManager.LoadModule(new Shell());
            _moduleManager.LoadModule(new DdeML());
            _moduleManager.LoadModule(new Sound());

            _disassembler = new Disassembler(this);

            this.InstructionHook = () =>
            {
                if (logExecution)
                {
                    _disassembled = null;
                    Log.WriteLine(_variableResolver.ResolveTokenizedString(_logExecutionFormat));
                }
            };
        }