Beispiel #1
0
        } /* process_story */

        /*
         * fix_dictionary
         *
         * Fix the end of text flag for each word in the dictionary. Some older games
         * are missing the end of text flag on some words. All the words are fixed up
         * so that they can be printed.
         */

        internal static void FixDictionary()
        {
            if (txio.header is null)
            {
                throw new InvalidOperationException("txio header was not initialized");
            }

            ulong address         = txio.header.dictionary;
            ulong separator_count = txio.ReadDataByte(ref address);

            address += separator_count;
            var word_size  = txio.ReadDataByte(ref address);
            var word_count = txio.ReadDataWord(ref address);

            for (int i = 1; i <= word_count; i++)
            {
                /* Check that the word is in non-paged memory before writing */

                if ((address + 4) < txio.header.resident_size)
                {
                    if ((uint)txio.header.version <= TxH.V3)
                    {
                        TxH.SetByte((int)address + 2, (byte)(TxH.GetByte(address + 2) | 0x80));
                    }
                    else
                    {
                        TxH.SetByte((int)address + 4, (byte)(TxH.GetByte(address + 4) | 0x80));
                    }
                }

                address += word_size;
            }
        } /* fix_dictionary */
Beispiel #2
0
        internal static void Configure(int min_version, int max_version)
        {
            if (gfp == null)
            {
                throw new InvalidOperationException("gfp not initialized.");
            }

            // buffer = new zbyte_t[tx_h.PAGE_SIZE];
            int i;

            buffer = new zbyte_t[gfp.Length];
            gfp.Read(buffer, 0, buffer.Length);

            //#if !defined(lint)
            //    assert (sizeof (zheader_t) == 64);
            //    assert (sizeof (zheader_t) <= PAGE_SIZE);
            //#endif /* !defined(lint) */

            // read_page(0, buffer);
            TxH.Datap = buffer;

            header = new TxH.ZHeaderT
            {
                version       = TxH.GetByte(TxH.H_VERSION),
                config        = TxH.GetByte(TxH.H_CONFIG),
                release       = TxH.GetWord(TxH.H_RELEASE),
                resident_size = TxH.GetWord(TxH.H_RESIDENT_SIZE),
                start_pc      = TxH.GetWord(TxH.H_START_PC),
                dictionary    = TxH.GetWord(TxH.H_DICTIONARY),
                objects       = TxH.GetWord(TxH.H_OBJECTS),
                globals       = TxH.GetWord(TxH.H_GLOBALS),
                dynamic_size  = TxH.GetWord(TxH.H_DYNAMIC_SIZE),
                flags         = TxH.GetWord(TxH.H_FLAGS)
            };
            for (i = 0; i < header.serial.Length; i++)
            {
                header.serial[i] = TxH.GetByte(TxH.H_SERIAL + i);
            }
            header.abbreviations       = TxH.GetWord(TxH.H_ABBREVIATIONS);
            header.file_size           = TxH.GetWord(TxH.H_FILE_SIZE);
            header.checksum            = TxH.GetWord(TxH.H_CHECKSUM);
            header.interpreter_number  = TxH.GetByte(TxH.H_INTERPRETER_NUMBER);
            header.interpreter_version = TxH.GetByte(TxH.H_INTERPRETER_VERSION);
            header.screen_rows         = TxH.GetByte(TxH.H_SCREEN_ROWS);
            header.screen_columns      = TxH.GetByte(TxH.H_SCREEN_COLUMNS);
            header.screen_width        = TxH.GetWord(TxH.H_SCREEN_WIDTH);
            header.screen_height       = TxH.GetWord(TxH.H_SCREEN_HEIGHT);
            if (header.version != TxH.V6)
            {
                header.font_width  = (byte)TxH.GetWord(TxH.H_FONT_WIDTH);
                header.font_height = TxH.GetByte(TxH.H_FONT_HEIGHT);
            }
            else
            {
                header.font_width  = (byte)TxH.GetWord(TxH.H_FONT_HEIGHT);
                header.font_height = TxH.GetByte(TxH.H_FONT_WIDTH);
            }
            header.routines_offset    = TxH.GetWord(TxH.H_ROUTINES_OFFSET);
            header.strings_offset     = TxH.GetWord(TxH.H_STRINGS_OFFSET);
            header.default_background = TxH.GetByte(TxH.H_DEFAULT_BACKGROUND);
            header.default_foreground = TxH.GetByte(TxH.H_DEFAULT_FOREGROUND);
            header.terminating_keys   = TxH.GetWord(TxH.H_TERMINATING_KEYS);
            header.line_width         = TxH.GetWord(TxH.H_LINE_WIDTH);
            header.specification_hi   = TxH.GetByte(TxH.H_SPECIFICATION_HI);
            header.specification_lo   = TxH.GetByte(TxH.H_SPECIFICATION_LO);
            header.alphabet           = TxH.GetWord(TxH.H_ALPHABET);
            header.mouse_table        = TxH.GetWord(TxH.H_MOUSE_TABLE);
            for (i = 0; i < header.name.Length; i++)
            {
                header.name[i] = TxH.GetByte(TxH.H_NAME + i);
            }

            if (header.version < (uint)min_version ||
                header.version > (uint)max_version ||
                ((uint)header.config & TxH.CONFIG_BYTE_SWAPPED) != 0)
            {
                throw new ArgumentException("\nFatal: wrong game or version\n");
            }

            if ((uint)header.version < TxH.V4)
            {
                story_scaler       = 2;
                story_shift        = 1;
                code_scaler        = 2;
                code_shift         = 1;
                property_mask      = TxH.P3_MAX_PROPERTIES - 1;
                property_size_mask = 0xe0;
            }
            else if ((uint)header.version < TxH.V6)
            {
                story_scaler       = 4;
                story_shift        = 2;
                code_scaler        = 4;
                code_shift         = 2;
                property_mask      = TxH.P4_MAX_PROPERTIES - 1;
                property_size_mask = 0x3f;
            }
            else if ((uint)header.version < TxH.V8)
            {
                story_scaler       = 8;
                story_shift        = 3;
                code_scaler        = 4;
                code_shift         = 2;
                property_mask      = TxH.P4_MAX_PROPERTIES - 1;
                property_size_mask = 0x3f;
            }
            else
            {
                story_scaler       = 8;
                story_shift        = 3;
                code_scaler        = 8;
                code_shift         = 3;
                property_mask      = TxH.P4_MAX_PROPERTIES - 1;
                property_size_mask = 0x3f;
            }

            /* Calculate the file size */

            if ((uint)header.file_size == 0)
            {
                throw new ArgumentException("Can't handle files with no length. Giving up!");
                // file_size = get_story_size();
            }

            file_size = (uint)header.version switch
            {
Beispiel #3
0
        /*
         * show_dictionary
         *
         * List the dictionary in the number of columns specified. If the number of
         * columns is one then also display the data associated with each word.
         */

        internal static void ShowDictionary(int columns)
        {
            ulong dict_address, word_address;
            uint  separator_count, word_size, length;
            int   i;
            bool  inform_flags = false;
            int   dictpar1     = 0;

            uint flag;

            if (txio.header is null)
            {
                throw new InvalidOperationException("txio header was not initialized");
            }

            var header = txio.header;

            /* Force default column count if none specified */

            if (columns == 0)
            {
                columns = ((uint)header.version < TxH.V4) ? 5 : 4;
            }

            /* Get dictionary configuration */

            ConfigureDictionary(out uint word_count, out ulong word_table_base, out ulong word_table_end);

            if (header.serial[0] is >= (byte)'0' and <= (byte)'9' &&
                header.serial[1] is >= (byte)'0' and <= (byte)'9' &&
                header.serial[2] is >= (byte)'0' and <= (byte)'1' &&
                header.serial[3] is >= (byte)'0' and <= (byte)'9' &&
                header.serial[4] is >= (byte)'0' and <= (byte)'3' &&
                header.serial[5] is >= (byte)'0' and <= (byte)'9' &&
                header.serial[0] != '8')
            {
                inform_flags = true;
            }

            txio.TxPrint("\n    **** Dictionary ****\n\n");

            /* Display the separators */

            dict_address    = word_table_base;
            separator_count = txio.ReadDataByte(ref dict_address);
            txio.TxPrint("  Word separators = \"");
            for (; separator_count > 0; separator_count--)
            {
                txio.TxPrintf("{0:c}", (char)txio.ReadDataByte(ref dict_address));
            }
            txio.TxPrint("\"\n");

            /* Get word size and count */

            word_size  = txio.ReadDataByte(ref dict_address);
            word_count = txio.ReadDataWord(ref dict_address);

            txio.TxPrintf("  Word count = {0}, word size = {0}\n", (int)word_count, (int)word_size);

            /* Display each entry in the dictionary */

            for (i = 1; (uint)i <= word_count; i++)
            {
                /* Set column breaks */

                if (columns == 1 || (i % columns) == 1)
                {
                    txio.TxPrint("\n");
                }

                txio.TxPrintf("[{0:d4}] ", i);

                /* Calculate address of next entry */

                word_address  = dict_address;
                dict_address += word_size;

                if (columns == 1)
                {
                    txio.TxPrintf("@ ${0:X2} ", (uint)word_address);
                }

                /* Display the text for the word */

                for (length = (uint)txio.DecodeText(ref word_address); length <= word_size; length++)
                {
                    txio.TxPrint(" ");
                }

                /* For a single column list also display the data for each entry */

                if (columns == 1)
                {
                    txio.TxPrint("[");
                    for (flag = 0; word_address < dict_address; flag++)
                    {
                        if (flag > 0)
                        {
                            txio.TxPrint(" ");
                        }
                        else
                        {
                            dictpar1 = TxH.GetByte(word_address);
                        }

                        txio.TxPrintf("{0:X2}", (uint)txio.ReadDataByte(ref word_address));
                    }
                    txio.TxPrint("]");

                    if (inform_flags)
                    {
                        if ((dictpar1 & TxH.NOUN) > 0)
                        {
                            txio.TxPrint(" <noun>");
                        }
                        if ((dictpar1 & TxH.PREP) > 0)
                        {
                            txio.TxPrint(" <prep>");
                        }
                        if ((dictpar1 & TxH.PLURAL) > 0)
                        {
                            txio.TxPrint(" <plural>");
                        }
                        if ((dictpar1 & TxH.META) > 0)
                        {
                            txio.TxPrint(" <meta>");
                        }
                        if ((dictpar1 & TxH.VERB_INFORM) > 0)
                        {
                            txio.TxPrint(" <verb>");
                        }
                    }
                    else if (header.version != TxH.V6)
                    {
                        flag = (uint)(dictpar1 & TxH.DATA_FIRST);
                        switch (flag)
                        {
                        case TxH.DIR_FIRST:
                            if ((dictpar1 & TxH.DIR) > 0)
                            {
                                txio.TxPrint(" <dir>");
                            }
                            break;

                        case TxH.ADJ_FIRST:
                            if ((dictpar1 & TxH.DESC) > 0)
                            {
                                txio.TxPrint(" <adj>");
                            }
                            break;

                        case TxH.VERB_FIRST:
                            if ((dictpar1 & TxH.VERB) > 0)
                            {
                                txio.TxPrint(" <verb>");
                            }
                            break;

                        case TxH.PREP_FIRST:
                            if ((dictpar1 & TxH.PREP) > 0)
                            {
                                txio.TxPrint(" <prep>");
                            }
                            break;
                        }
                        if ((dictpar1 & TxH.DIR) > 0 && (flag != TxH.DIR_FIRST))
                        {
                            txio.TxPrint(" <dir>");
                        }
                        if ((dictpar1 & TxH.DESC) > 0 && (flag != TxH.ADJ_FIRST))
                        {
                            txio.TxPrint(" <adj>");
                        }
                        if ((dictpar1 & TxH.VERB) > 0 && (flag != TxH.VERB_FIRST))
                        {
                            txio.TxPrint(" <verb>");
                        }
                        if ((dictpar1 & TxH.PREP) > 0 && (flag != TxH.PREP_FIRST))
                        {
                            txio.TxPrint(" <prep>");
                        }
                        if ((dictpar1 & TxH.NOUN) > 0)
                        {
                            txio.TxPrint(" <noun>");
                        }
                        if ((dictpar1 & TxH.SPECIAL) > 0)
                        {
                            txio.TxPrint(" <special>");
                        }
                    }
                }
            }
            txio.TxPrint("\n");
        }/* show_dictionary */