Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
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);
        }