예제 #1
0
        public ZAbbreviations(ZHeader header, IMemoryManager manager)
        {
            var abbreviationsTable = manager.AsSpan(header.AbbreviationsTable).ToArray();
            var dynamicMemory      = manager.AsSpan(0, header.DynamicMemorySize);
            var abbrevs            = new List <string>();
            var anyMoreEntries     = true;

            var abbrIdx = 0;

            while (anyMoreEntries && abbrIdx < 96)
            {
                var addr = abbreviationsTable.GetUShort((ushort)(abbrIdx * 2));
                anyMoreEntries = addr != 0;
                if (anyMoreEntries)
                {
                    var zStr = ZsciiString.Get(dynamicMemory.AsSpan((ushort)(addr * 2)), null, header);
                    abbrevs.Add(zStr);
                    abbrIdx++;
                }
            }

//            for (int abbrIdx = 0; abbrIdx < 96 ; abbrIdx++)
//            {
//                var addr = abbreviationsTable.GetUShort((ushort) (abbrIdx * 2));
//
//                if (addr == 0) break;
//
//                var zStr = ZsciiString.Get(dynamicMemory.AsSpan((ushort)(addr * 2)), null);
//                abbrevs.Add(zStr);
//            }

            Abbreviations = abbrevs.ToArray();
        }
예제 #2
0
        /// <summary>
        /// Constructor that will maintain an objects property in zmemory
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="propAddress"></param>
        /// <param name="header"></param>
        public ZProperty(IMemoryManager manager, ushort propAddress, ZHeader header)
        {
            _manager        = manager;
            _header         = header;
            PropertyAddress = propAddress;
            var ptr      = propAddress;
            var propByte = _manager.Get(PropertyAddress);

            if (_header.Version > 3 && (byte)(propByte & Bits.Bit7) == Bits.Bit7)
            {
                Number = GetPropertyNumber(propByte);
                Length = (ushort)(_manager.Get(++ptr) & 0x3F);

                if (Length == 0)
                {
                    Length = 64;
                }
            }
            else
            {
                Number = GetPropertyNumber(propByte);
                Length = GetPropertySize(propByte);
            }

            DataAddress = (ushort)(PropertyAddress + 1);
            _data       = _manager.AsSpan(DataAddress, 2);
            BytesUsed   = (ushort)(Length + 1);
        }
예제 #3
0
        public ZObjectTree(ZHeader header,
                           IMemoryManager manager,
                           ZAbbreviations abbreviations)
        {
            _header = header;
            var objectTableData = manager.AsSpan(header.ObjectTable);// memory.AsSpan(header.ObjectTable);

            var(defaultProps, ptr) = GetDefaultProps(objectTableData);
            DefaultProperties      = defaultProps;

            var lastObject = false;

            ushort objNumber = 1;

            _dict = new Dictionary <ushort, IZMachineObject>();

            while (!lastObject && objNumber < 255)
            {
                // Objects end when the properties start!
                ushort objectAddress = (ushort)(header.ObjectTable + ptr);

                var min = _dict.Values.Any() ? _dict.Values.Min(v => v.PropertiesAddress) : ushort.MaxValue;
                lastObject = objectAddress >= min;
                if (!lastObject)
                {
                    var zObj = new ZMachineObject(objNumber, objectAddress, header, manager, abbreviations, DefaultProperties);
                    _dict.Add(objNumber, zObj);
                    ptr += zObj.BytesRead;

                    objNumber++;
                }
            }
        }
예제 #4
0
        public ZDictionary(ZHeader header, IMemoryManager manager, ZAbbreviations abbreviations)
        {
            var    bytes = manager.AsSpan(header.Dictionary);
            ushort addr  = 0;

            var numOfInputCodes = bytes[addr++];

            InputCodes = bytes.AsSpan(addr, numOfInputCodes).ToArray();
            addr      += numOfInputCodes;

            var zsciiStringArray = new ZsciiStringArray(bytes.AsSpan(addr), abbreviations, header);

            Words       = zsciiStringArray.Words;
            EntryLength = zsciiStringArray.EntryLength;
            WordStart   = (ushort)(addr + zsciiStringArray.WordStart);
        }