public static ushort GetFirstProperty(this ZMachine aMachine, ushort aObject) { ushort xObjectAddress = aMachine.GetObjectAddress(aObject); aMachine.Memory.GetWord(xObjectAddress + 7, out ushort propTable); aMachine.Memory.GetByte(propTable, out byte nameSize); propTable += (ushort)(2 * nameSize + 1); return(propTable); }
public static string GetObjectName(this ZMachine aMachine, ushort aObject) { ushort objAddress = aMachine.GetObjectAddress(aObject); if (aMachine.Story.Header.Version <= FileVersion.V3) { objAddress += O1_PROPERTY_OFFSET; } else { objAddress += O4_PROPERTY_OFFSET; } aMachine.Memory.GetWord(objAddress, out ushort nameAddress); return(ZText.DecodeString((ushort)(nameAddress + 1))); }
public static void UnlinkObject(this ZMachine aMachine, ushort aObject) { if (aObject == 0) { return; } ushort xObjectAddress = aMachine.GetObjectAddress(aObject); if (aMachine.Story.Header.Version <= FileVersion.V3) { byte zero = 0; xObjectAddress += O1_PARENT; aMachine.Memory.GetByte(xObjectAddress, out byte xParentObject); if (xParentObject == 0) { return; } aMachine.Memory.SetByte(xObjectAddress, zero); xObjectAddress += O1_SIBLING - O1_PARENT; aMachine.Memory.GetByte(xObjectAddress, out byte xOlderSibling); aMachine.Memory.SetByte(xObjectAddress, zero); ushort xParentAddress = (ushort)(aMachine.GetObjectAddress(xParentObject) + O1_CHILD); aMachine.Memory.GetByte(xParentAddress, out byte xYoungerSibling); if (xYoungerSibling == aObject) { aMachine.Memory.SetByte(xParentAddress, xOlderSibling); } else { ushort xSiblingAddress; do { xSiblingAddress = (ushort)(aMachine.GetObjectAddress(xYoungerSibling) + O1_SIBLING); aMachine.Memory.GetByte(xSiblingAddress, out xYoungerSibling); } while (xYoungerSibling != aObject); aMachine.Memory.SetByte(xSiblingAddress, xOlderSibling); } } else { ushort zero = 0; xObjectAddress += O4_PARENT; aMachine.Memory.GetWord(xObjectAddress, out ushort xParentObject); if (xParentObject == 0) { return; } aMachine.Memory.SetWord(xObjectAddress, zero); xObjectAddress += O4_SIBLING - O4_PARENT; aMachine.Memory.GetWord(xObjectAddress, out ushort xOlderSibling); aMachine.Memory.SetWord(xObjectAddress, zero); ushort xParentAddress = (ushort)(aMachine.GetObjectAddress(xParentObject) + O4_CHILD); aMachine.Memory.GetWord(xParentAddress, out ushort xYoungerSibling); if (xYoungerSibling == aObject) { aMachine.Memory.SetWord(xParentAddress, xOlderSibling); } else { ushort xSiblingAddress; do { xSiblingAddress = (ushort)(aMachine.GetObjectAddress(xYoungerSibling) + O4_SIBLING); aMachine.Memory.GetWord(xYoungerSibling, out xYoungerSibling); } while (xYoungerSibling != aObject); aMachine.Memory.SetWord(xSiblingAddress, xOlderSibling); } } }