Exemple #1
0
        public void Run()
        {
            //DebugOut("Z-machine version {0}", zversion);

            ResetHeaderFields(true);
            io.EraseWindow(-1);

            pc = (ushort)GetWord(0x06);

            cache = new LruCache <int, CachedCode>(cacheSize);

#if BENCHMARK
            // reset performance stats
            cycles       = 0;
            startTime    = Environment.TickCount;
            creditedTime = 0;
            cacheHits    = 0;
            cacheMisses  = 0;
#endif

            running = true;
            try
            {
                JitLoop();
            }
            finally
            {
                running = false;
                if (cmdRdr != null)
                {
                    cmdRdr.Dispose();
                    cmdRdr = null;
                }
                if (cmdWtr != null)
                {
                    cmdWtr.Dispose();
                    cmdWtr = null;
                }
            }

#if BENCHMARK
            // show performance report
            int      billedMillis = Environment.TickCount - startTime - creditedTime;
            TimeSpan billedTime   = new TimeSpan(10000 * billedMillis);
            io.PutString("\n\n*** Performance Report ***\n");
            io.PutString(string.Format("Cycles: {0}\nTime: {1}\nSpeed: {2:0.0} cycles/sec\n",
                                       cycles,
                                       billedTime,
                                       cycles * 1000 / (double)billedMillis));
#if DISABLE_CACHE
            io.PutString("Code cache was disabled.\n");
#else
            io.PutString(string.Format("Final cache use: {1} instructions in {0} fragments\n",
                                       cache.Count,
                                       cache.CurrentSize));
            io.PutString(string.Format("Peak cache use: {0} instructions\n", cache.PeakSize));
            io.PutString(string.Format("Cache hits: {0}. Misses: {1}.\n", cacheHits, cacheMisses));
#endif // DISABLE_CACHE
#endif // BENCHMARK
        }
        private void SetOutputStream(short num, ushort address)
        {
            bool enabled = true;

            if (num < 0)
            {
                num     = (short)-num;
                enabled = false;
            }

            switch (num)
            {
            case 1:
                // normal
                normalOutput = enabled;
                break;

            case 2:
                // transcript
                io.Transcripting = enabled;
                break;

            case 3:
                // memory (nestable up to 16 levels)
                if (enabled)
                {
                    if (tableOutputAddrStack.Count == 16)
                    {
                        throw new Exception("Output stream 3 nested too deeply");
                    }
                    if (address < 64 || address + 1 >= romStart)
                    {
                        throw new Exception("Output stream 3 address is out of range");
                    }

                    tableOutput = true;
                    tableOutputAddrStack.Push(address);
                    tableOutputBufferStack.Push(new List <byte>());
                }
                else if (tableOutput)
                {
                    address = tableOutputAddrStack.Pop();
                    List <byte> buffer = tableOutputBufferStack.Pop();

                    int len = Math.Min(buffer.Count, romStart - address - 2);
                    SetWord(address, (short)len);
                    for (int i = 0; i < len; i++)
                    {
                        SetByte(address + 2 + i, buffer[i]);
                    }

                    if (tableOutputAddrStack.Count == 0)
                    {
                        tableOutput = false;
                    }
                }
                break;

            case 4:
                // player's commands
                if (enabled)
                {
                    Stream cmdStream = io.OpenCommandFile(true);
                    if (cmdStream != null)
                    {
                        if (cmdWtr != null)
                        {
                            cmdWtr.Dispose();
                        }

                        try
                        {
                            cmdWtr = new CommandFileWriter(cmdStream);
                        }
                        catch
                        {
                            cmdWtr = null;
                        }
                    }
                }
                else
                {
                    if (cmdWtr != null)
                    {
                        cmdWtr.Dispose();
                        cmdWtr = null;
                    }
                }
                break;

            default:
                throw new Exception("Invalid output stream #" + num.ToString());
            }
        }
Exemple #3
0
        private void SetOutputStream(short num, ushort address)
        {
            bool enabled = true;
            if (num < 0)
            {
                num = (short)-num;
                enabled = false;
            }

            switch (num)
            {
                case 1:
                    // normal
                    normalOutput = enabled;
                    break;

                case 2:
                    // transcript
                    io.Transcripting = enabled;
                    break;

                case 3:
                    // memory (nestable up to 16 levels)
                    if (enabled)
                    {
                        if (tableOutputAddrStack.Count == 16)
                            throw new Exception("Output stream 3 nested too deeply");
                        if (address < 64 || address + 1 >= romStart)
                            throw new Exception("Output stream 3 address is out of range");

                        tableOutput = true;
                        tableOutputAddrStack.Push(address);
                        tableOutputBufferStack.Push(new List<byte>());
                    }
                    else if (tableOutput)
                    {
                        address = tableOutputAddrStack.Pop();
                        List<byte> buffer = tableOutputBufferStack.Pop();

                        int len = Math.Min(buffer.Count, romStart - address - 2);
                        SetWord(address, (short)len);
                        for (int i = 0; i < len; i++)
                            SetByte(address + 2 + i, buffer[i]);

                        if (tableOutputAddrStack.Count == 0)
                            tableOutput = false;
                    }
                    break;

                case 4:
                    // player's commands
                    if (enabled)
                    {
                        Stream cmdStream = io.OpenCommandFile(true);
                        if (cmdStream != null)
                        {
                            if (cmdWtr != null)
                                cmdWtr.Dispose();

                            try
                            {
                                cmdWtr = new CommandFileWriter(cmdStream);
                            }
                            catch
                            {
                                cmdWtr = null;
                            }
                        }
                    }
                    else
                    {
                        if (cmdWtr != null)
                        {
                            cmdWtr.Dispose();
                            cmdWtr = null;
                        }
                    }
                    break;

                default:
                    throw new Exception("Invalid output stream #" + num.ToString());
            }
        }
Exemple #4
0
        public void Run()
        {
            //DebugOut("Z-machine version {0}", zversion);

            ResetHeaderFields(true);
            io.EraseWindow(-1);
            if (zversion <= 4)
                io.ScrollFromBottom = true;

            if (zversion == 6)
            {
                EnterFunctionImpl(GetWord(0x06), null, -1, -1);
            }
            else
            {
                pc = (ushort)GetWord(0x06);
            }

            cache = new LruCache<int, CachedCode>(cacheSize);

#if BENCHMARK
            // reset performance stats
            cycles = 0;
            startTime = Environment.TickCount;
            creditedTime = 0;
            cacheHits = 0;
            cacheMisses = 0;
#endif

            running = true;
            try
            {
                JitLoop();
            }
            finally
            {
                running = false;
                if (cmdRdr != null)
                {
                    cmdRdr.Dispose();
                    cmdRdr = null;
                }
                if (cmdWtr != null)
                {
                    cmdWtr.Dispose();
                    cmdWtr = null;
                }
            }

#if BENCHMARK
            // show performance report
            int billedMillis = Environment.TickCount - startTime - creditedTime;
            TimeSpan billedTime = new TimeSpan(10000 * billedMillis);
            io.PutString("\n\n*** Performance Report ***\n");
            io.PutString(string.Format("Cycles: {0}\nTime: {1}\nSpeed: {2:0.0} cycles/sec\n",
                cycles,
                billedTime,
                cycles * 1000 / (double)billedMillis));
#if DISABLE_CACHE
            io.PutString("Code cache was disabled.\n");
#else
            io.PutString(string.Format("Final cache use: {1} instructions in {0} fragments\n",
                cache.Count,
                cache.CurrentSize));
            io.PutString(string.Format("Peak cache use: {0} instructions\n", cache.PeakSize));
            io.PutString(string.Format("Cache hits: {0}. Misses: {1}.\n", cacheHits, cacheMisses));
            MeasureCacheOverlap();
#endif // DISABLE_CACHE
#endif // BENCHMARK
        }