public ZAttributes(IMemoryManager manager, ushort address, ZHeader header) { _address = address; _manager = manager; _header = header; _attributesLength = AttributesLength(header); }
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++; } } }
/// <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); }
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(); }
public ZMemory(byte[] data, Action restart) { _restart = restart; Header = new ZHeader(data.AsSpan(0, 31)); if (Header.Version > 5) { throw new NotSupportedException("ZMachine > V5 not currently supported"); } // Version specific offsets Offsets = VersionedOffsets.For(Header.Version); Manager = new MemoryManager(data); // ZMachine tables Abbreviations = new ZAbbreviations(Header, Manager); Dictionary = new ZDictionary(Header, Manager, Abbreviations); ObjectTree = new ZObjectTree(Header, Manager, Abbreviations); Globals = new ZGlobals(Header, Manager); // Custom Stack with some abstractions for better testing. Stack = new ZStack(); // Simple managers to abstract variable and argument usage VariableManager = new VariableManager(Stack, Globals); OperandManager = new OperandManager(Manager, Stack, VariableManager); }
public ZsciiString(Span <byte> data, ZAbbreviations abbreviations, ZHeader header, int zsciiWordsToUse = int.MaxValue) { _v2CharProvider = new V2CharProvider(abbreviations); _header = header; var chars = GetZsciiChars(data, zsciiWordsToUse); BytesUsed = (ushort)(chars.Count / 3 * 2); String = DecodeZsciiChars(chars, abbreviations); }
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); }
public ZsciiStringArray(Span <byte> data, ZAbbreviations abbreviations, ZHeader header) { var bytes = data.ToArray(); ushort ptr = 0; EntryLength = bytes[ptr++]; var numEntries = bytes.GetUShort(ptr); ptr += 2; WordStart = ptr; Words = new string[numEntries]; for (var i = 0; i < numEntries; i++) { var stringData = bytes.AsSpan(ptr); var zStr = new ZsciiString(stringData, abbreviations, header, header.Version <= 3 ? 2 : 3); ptr += EntryLength; Words[i] = zStr.String; } }
private ushort AttributesLength(ZHeader header) => (ushort)(header.Version <= 3 ? 4 : 6);
public static string Get(Span <byte> data, ZAbbreviations abbreviations, ZHeader header) => new ZsciiString(data, abbreviations, header).String;
public ZGlobals(ZHeader header, IMemoryManager manager) { _header = header; _manager = manager; }