예제 #1
0
        private void StoryService_StoryClosing(object sender, StoryClosingEventArgs e)
        {
            machine            = null;
            reader             = null;
            currentInstruction = null;
            hasStepped         = false;

            ChangeState(DebuggerState.Unavailable);

            var handler = MachineDestroyed;

            if (handler != null)
            {
                handler(this, new MachineDestroyedEventArgs());
            }
        }
예제 #2
0
        private void StoryService_StoryOpened(object sender, StoryOpenedEventArgs e)
        {
            e.Story.RegisterInterpreter(new Interpreter());
            machine = new InterpretedZMachine(e.Story);
            reader  = new InstructionReader(machine.PC, e.Story.Memory);

            machine.SetRandomSeed(42);
            machine.Quit += Machine_Quit;

            ChangeState(DebuggerState.Stopped);

            var handler = MachineCreated;

            if (handler != null)
            {
                handler(this, new MachineCreatedEventArgs());
            }
        }
예제 #3
0
        public override void Run()
        {
            MarkProfile("Reading story");

            var story     = ReadStory(StoryFilePath);
            var processor = new InterpretedZMachine(story);

            var    done       = false;
            Action doneAction = () => { done = true; };

            var mockScreen = new MockScreen(ScriptFilePath, doneAction);

            processor.SetRandomSeed(42);
            processor.RegisterScreen(mockScreen);

            processor.Quit += (s, e) => { done = true; };

            MarkProfile("Stepping...");

            var sw = Stopwatch.StartNew();

            try
            {
                while (!done)
                {
                    processor.Step();
                }
            }
            catch (Exception ex)
            {
                MarkProfile(string.Format("{0}: {1}", ex.GetType().FullName, ex.Message));
            }

            sw.Stop();

            MarkProfile("Done stepping");

            Console.WriteLine();
            Console.WriteLine("{0:#,#} instructions", processor.InstructionCount);
            Console.WriteLine("{0:#,#} calls", processor.CallCount);
            Console.WriteLine();
            Console.WriteLine("{0:#,0.##########} seconds", (double)sw.ElapsedTicks / (double)Stopwatch.Frequency);
            Console.WriteLine("{0:#,0.##########} seconds per instruction", ((double)sw.ElapsedTicks / (double)Stopwatch.Frequency) / (double)processor.InstructionCount);
        }