From e0c021890b8ab93f198b8bdbf049144a59a3c0ce Mon Sep 17 00:00:00 2001 From: David Griffith Date: Sat, 21 Sep 2019 17:28:54 -0700 Subject: [PATCH] Convert object.c to K&R style. --- src/common/object.c | 1261 +++++++++++++++++++------------------------ 1 file changed, 568 insertions(+), 693 deletions(-) diff --git a/src/common/object.c b/src/common/object.c index 699035b..fc17976 100644 --- a/src/common/object.c +++ b/src/common/object.c @@ -41,27 +41,23 @@ * Calculate the address of an object. * */ - -static zword object_address (zword obj) +static zword object_address(zword obj) { - /* Check object number */ - - if (obj > ((h_version <= V3) ? 255 : MAX_OBJECT)) { - print_string("@Attempt to address illegal object "); - print_num(obj); - print_string(". This is normally fatal."); - new_line(); - runtime_error (ERR_ILL_OBJ); - } - - /* Return object address */ - - if (h_version <= V3) - return h_objects + ((obj - 1) * O1_SIZE + 62); - else - return h_objects + ((obj - 1) * O4_SIZE + 126); + /* Check object number */ + if (obj > ((h_version <= V3) ? 255 : MAX_OBJECT)) { + print_string("@Attempt to address illegal object "); + print_num(obj); + print_string(". This is normally fatal."); + new_line(); + runtime_error (ERR_ILL_OBJ); + } -}/* object_address */ + /* Return object address */ + if (h_version <= V3) + return h_objects + ((obj - 1) * O1_SIZE + 62); + else + return h_objects + ((obj - 1) * O4_SIZE + 126); +} /* object_address */ /* @@ -70,25 +66,22 @@ static zword object_address (zword obj) * Return the address of the given object's name. * */ -zword object_name (zword object) +zword object_name(zword object) { - zword obj_addr; - zword name_addr; - - obj_addr = object_address (object); - - /* The object name address is found at the start of the properties */ + zword obj_addr; + zword name_addr; - if (h_version <= V3) - obj_addr += O1_PROPERTY_OFFSET; - else - obj_addr += O4_PROPERTY_OFFSET; + obj_addr = object_address(object); - LOW_WORD (obj_addr, name_addr) + /* The object name address is found at the start of the properties */ + if (h_version <= V3) + obj_addr += O1_PROPERTY_OFFSET; + else + obj_addr += O4_PROPERTY_OFFSET; + LOW_WORD(obj_addr, name_addr) - return name_addr; - -}/* object_name */ + return name_addr; +} /* object_name */ /* @@ -98,24 +91,20 @@ zword object_name (zword object) * an object. * */ -static zword first_property (zword obj) +static zword first_property(zword obj) { - zword prop_addr; - zbyte size; - - /* Fetch address of object name */ - - prop_addr = object_name (obj); - - /* Get length of object name */ + zword prop_addr; + zbyte size; - LOW_BYTE (prop_addr, size) + /* Fetch address of object name */ + prop_addr = object_name (obj); - /* Add name length to pointer */ + /* Get length of object name */ + LOW_BYTE(prop_addr, size) - return prop_addr + 1 + 2 * size; - -}/* first_property */ + /* Add name length to pointer */ + return prop_addr + 1 + 2 * size; +} /* first_property */ /* @@ -124,35 +113,29 @@ static zword first_property (zword obj) * Calculate the address of the next property in a property list. * */ -static zword next_property (zword prop_addr) +static zword next_property(zword prop_addr) { - zbyte value; - - /* Load the current property id */ + zbyte value; - LOW_BYTE (prop_addr, value) - prop_addr++; - - /* Calculate the length of this property */ - - if (h_version <= V3) - value >>= 5; - else if (!(value & 0x80)) - value >>= 6; - else { - - LOW_BYTE (prop_addr, value) - value &= 0x3f; - - if (value == 0) value = 64; /* demanded by Spec 1.0 */ - - } + /* Load the current property id */ + LOW_BYTE(prop_addr, value) + prop_addr++; - /* Add property length to current property pointer */ + /* Calculate the length of this property */ - return prop_addr + value + 1; + if (h_version <= V3) + value >>= 5; + else if (!(value & 0x80)) + value >>= 6; + else { + LOW_BYTE(prop_addr, value) + value &= 0x3f; + if (value == 0) value = 64; /* demanded by Spec 1.0 */ + } -}/* next_property */ + /* Add property length to current property pointer */ + return prop_addr + value + 1; +} /* next_property */ /* @@ -161,100 +144,91 @@ static zword next_property (zword prop_addr) * Unlink an object from its parent and siblings. * */ -static void unlink_object (zword object) +static void unlink_object(zword object) { - zword obj_addr; - zword parent_addr; - zword sibling_addr; - - if (object == 0) { - runtime_error (ERR_REMOVE_OBJECT_0); - return; - } - - obj_addr = object_address (object); - - if (h_version <= V3) { - - zbyte parent; - zbyte younger_sibling; - zbyte older_sibling; - zbyte zero = 0; - - /* Get parent of object, and return if no parent */ + zword obj_addr; + zword parent_addr; + zword sibling_addr; - obj_addr += O1_PARENT; - LOW_BYTE (obj_addr, parent) - if (!parent) - return; - - /* Get (older) sibling of object and set both parent and sibling - pointers to 0 */ - - SET_BYTE (obj_addr, zero) - obj_addr += O1_SIBLING - O1_PARENT; - LOW_BYTE (obj_addr, older_sibling) - SET_BYTE (obj_addr, zero) - - /* Get first child of parent (the youngest sibling of the object) */ - - parent_addr = object_address (parent) + O1_CHILD; - LOW_BYTE (parent_addr, younger_sibling) - - /* Remove object from the list of siblings */ - - if (younger_sibling == object) - SET_BYTE (parent_addr, older_sibling) - else { - do { - sibling_addr = object_address (younger_sibling) + O1_SIBLING; - LOW_BYTE (sibling_addr, younger_sibling) - } while (younger_sibling != object); - SET_BYTE (sibling_addr, older_sibling) + if (object == 0) { + runtime_error(ERR_REMOVE_OBJECT_0); + return; } - } else { - - zword parent; - zword younger_sibling; - zword older_sibling; - zword zero = 0; - - /* Get parent of object, and return if no parent */ - - obj_addr += O4_PARENT; - LOW_WORD (obj_addr, parent) - if (!parent) - return; - - /* Get (older) sibling of object and set both parent and sibling - pointers to 0 */ - - SET_WORD (obj_addr, zero) - obj_addr += O4_SIBLING - O4_PARENT; - LOW_WORD (obj_addr, older_sibling) - SET_WORD (obj_addr, zero) - - /* Get first child of parent (the youngest sibling of the object) */ - - parent_addr = object_address (parent) + O4_CHILD; - LOW_WORD (parent_addr, younger_sibling) - - /* Remove object from the list of siblings */ - - if (younger_sibling == object) - SET_WORD (parent_addr, older_sibling) - else { - do { - sibling_addr = object_address (younger_sibling) + O4_SIBLING; - LOW_WORD (sibling_addr, younger_sibling) - } while (younger_sibling != object); - SET_WORD (sibling_addr, older_sibling) + obj_addr = object_address (object); + + if (h_version <= V3) { + zbyte parent; + zbyte younger_sibling; + zbyte older_sibling; + zbyte zero = 0; + + /* Get parent of object, and return if no parent */ + obj_addr += O1_PARENT; + LOW_BYTE(obj_addr, parent) + if (!parent) + return; + + /* Get (older) sibling of object and set both + * parent and sibling pointers to 0 */ + SET_BYTE(obj_addr, zero) + obj_addr += O1_SIBLING - O1_PARENT; + LOW_BYTE(obj_addr, older_sibling) + SET_BYTE(obj_addr, zero) + + /* Get first child of parent (the youngest sibling + * of the object) */ + parent_addr = object_address(parent) + O1_CHILD; + LOW_BYTE(parent_addr, younger_sibling) + + /* Remove object from the list of siblings */ + if (younger_sibling == object) + SET_BYTE(parent_addr, older_sibling) + else { + do { + sibling_addr = object_address(younger_sibling) + + O1_SIBLING; + LOW_BYTE(sibling_addr, younger_sibling) + } while (younger_sibling != object); + SET_BYTE(sibling_addr, older_sibling) + } + } else { + zword parent; + zword younger_sibling; + zword older_sibling; + zword zero = 0; + + /* Get parent of object, and return if no parent */ + obj_addr += O4_PARENT; + LOW_WORD(obj_addr, parent) + if (!parent) + return; + + /* Get (older) sibling of object and set both parent + * and sibling pointers to 0 */ + SET_WORD(obj_addr, zero) + obj_addr += O4_SIBLING - O4_PARENT; + LOW_WORD(obj_addr, older_sibling) + SET_WORD(obj_addr, zero) + + /* Get first child of parent (the youngest sibling + * of the object) */ + parent_addr = object_address(parent) + O4_CHILD; + LOW_WORD(parent_addr, younger_sibling) + + /* Remove object from the list of siblings */ + if (younger_sibling == object) + SET_WORD(parent_addr, older_sibling) + else { + do { + sibling_addr = object_address(younger_sibling) + + O4_SIBLING; + LOW_WORD(sibling_addr, younger_sibling) + } while (younger_sibling != object); + SET_WORD(sibling_addr, older_sibling) + } } - - } - -}/* unlink_object */ +} /* unlink_object */ /* @@ -264,45 +238,42 @@ static void unlink_object (zword object) * zargs[1] = number of attribute to be cleared * */ -void z_clear_attr (void) +void z_clear_attr(void) { - zword obj_addr; - zbyte value; + zword obj_addr; + zbyte value; - if (story_id == SHERLOCK) - if (zargs[1] == 48) - return; + if (story_id == SHERLOCK) + if (zargs[1] == 48) + return; - if (zargs[1] > ((h_version <= V3) ? 31 : 47)) - runtime_error (ERR_ILL_ATTR); + if (zargs[1] > ((h_version <= V3) ? 31 : 47)) + runtime_error(ERR_ILL_ATTR); - /* If we are monitoring attribute assignment display a short note */ + /* If we are monitoring attribute assignment display a short note */ - if (f_setup.attribute_assignment) { - stream_mssg_on (); - print_string ("@clear_attr "); - print_object (zargs[0]); - print_string (" "); - print_num (zargs[1]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_CLEAR_ATTR_0); - return; - } - - /* Get attribute address */ - - obj_addr = object_address (zargs[0]) + zargs[1] / 8; + if (f_setup.attribute_assignment) { + stream_mssg_on(); + print_string("@clear_attr "); + print_object(zargs[0]); + print_string(" "); + print_num(zargs[1]); + stream_mssg_off(); + } - /* Clear attribute bit */ + if (zargs[0] == 0) { + runtime_error(ERR_CLEAR_ATTR_0); + return; + } - LOW_BYTE (obj_addr, value) - value &= ~(0x80 >> (zargs[1] & 7)); - SET_BYTE (obj_addr, value) + /* Get attribute address */ + obj_addr = object_address(zargs[0]) + zargs[1] / 8; -}/* z_clear_attr */ + /* Clear attribute bit */ + LOW_BYTE(obj_addr, value) + value &= ~(0x80 >> (zargs[1] & 7)); + SET_BYTE(obj_addr, value) +} /* z_clear_attr */ /* @@ -312,58 +283,47 @@ void z_clear_attr (void) * zargs[1] = second object * */ -void z_jin (void) +void z_jin(void) { - zword obj_addr; - - /* If we are monitoring object locating display a short note */ - - if (f_setup.object_locating) { - stream_mssg_on (); - print_string ("@jin "); - print_object (zargs[0]); - print_string (" "); - print_object (zargs[1]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_JIN_0); - branch (0 == zargs[1]); - return; - } - - obj_addr = object_address (zargs[0]); - - if (h_version <= V3) { - - zbyte parent; - - /* Get parent id from object */ - - obj_addr += O1_PARENT; - LOW_BYTE (obj_addr, parent) - - /* Branch if the parent is obj2 */ - - branch (parent == zargs[1]); - - } else { - - zword parent; + zword obj_addr; + + /* If we are monitoring object locating display a short note */ + if (f_setup.object_locating) { + stream_mssg_on(); + print_string("@jin "); + print_object(zargs[0]); + print_string(" "); + print_object(zargs[1]); + stream_mssg_off(); + } - /* Get parent id from object */ + if (zargs[0] == 0) { + runtime_error(ERR_JIN_0); + branch(0 == zargs[1]); + return; + } - obj_addr += O4_PARENT; - LOW_WORD (obj_addr, parent) + obj_addr = object_address(zargs[0]); - /* Branch if the parent is obj2 */ + if (h_version <= V3) { + zbyte parent; - branch (parent == zargs[1]); + /* Get parent id from object */ + obj_addr += O1_PARENT; + LOW_BYTE(obj_addr, parent) - } + /* Branch if the parent is obj2 */ + branch (parent == zargs[1]); + } else { + zword parent; + /* Get parent id from object */ + obj_addr += O4_PARENT; + LOW_WORD(obj_addr, parent) -}/* z_jin */ + /* Branch if the parent is obj2 */ + branch (parent == zargs[1]); + } +} /* z_jin */ /* @@ -372,59 +332,50 @@ void z_jin (void) * zargs[0] = object * */ -void z_get_child (void) +void z_get_child(void) { - zword obj_addr; - - /* If we are monitoring object locating display a short note */ - - if (f_setup.object_locating) { - stream_mssg_on (); - print_string ("@get_child "); - print_object (zargs[0]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_GET_CHILD_0); - store (0); - branch (FALSE); - return; - } - - obj_addr = object_address (zargs[0]); - - if (h_version <= V3) { - - zbyte child; + zword obj_addr; - /* Get child id from object */ + /* If we are monitoring object locating display a short note */ - obj_addr += O1_CHILD; - LOW_BYTE (obj_addr, child) - - /* Store child id and branch */ - - store (child); - branch (child); - - } else { + if (f_setup.object_locating) { + stream_mssg_on(); + print_string("@get_child "); + print_object(zargs[0]); + stream_mssg_off(); + } - zword child; + if (zargs[0] == 0) { + runtime_error(ERR_GET_CHILD_0); + store(0); + branch(FALSE); + return; + } - /* Get child id from object */ + obj_addr = object_address (zargs[0]); - obj_addr += O4_CHILD; - LOW_WORD (obj_addr, child) + if (h_version <= V3) { + zbyte child; - /* Store child id and branch */ + /* Get child id from object */ + obj_addr += O1_CHILD; + LOW_BYTE(obj_addr, child) - store (child); - branch (child); + /* Store child id and branch */ + store(child); + branch(child); + } else { + zword child; - } + /* Get child id from object */ + obj_addr += O4_CHILD; + LOW_WORD(obj_addr, child) -}/* z_get_child */ + /* Store child id and branch */ + store(child); + branch(child); + } +} /* z_get_child */ /* @@ -434,48 +385,40 @@ void z_get_child (void) * zargs[1] = address of current property (0 gets the first property) * */ -void z_get_next_prop (void) +void z_get_next_prop(void) { - zword prop_addr; - zbyte value; - zbyte mask; - - if (zargs[0] == 0) { - runtime_error (ERR_GET_NEXT_PROP_0); - store (0); - return; - } - - /* Property id is in bottom five (six) bits */ - - mask = (h_version <= V3) ? 0x1f : 0x3f; - - /* Load address of first property */ - - prop_addr = first_property (zargs[0]); - - if (zargs[1] != 0) { - - /* Scan down the property list */ - - do { - LOW_BYTE (prop_addr, value) - prop_addr = next_property (prop_addr); - } while ((value & mask) > zargs[1]); - - /* Exit if the property does not exist */ + zword prop_addr; + zbyte value; + zbyte mask; + + if (zargs[0] == 0) { + runtime_error(ERR_GET_NEXT_PROP_0); + store(0); + return; + } - if ((value & mask) != zargs[1]) - runtime_error (ERR_NO_PROP); + /* Property id is in bottom five (six) bits */ + mask = (h_version <= V3) ? 0x1f : 0x3f; - } + /* Load address of first property */ + prop_addr = first_property(zargs[0]); - /* Return the property id */ + if (zargs[1] != 0) { + /* Scan down the property list */ + do { + LOW_BYTE(prop_addr, value) + prop_addr = next_property(prop_addr); + } while ((value & mask) > zargs[1]); - LOW_BYTE (prop_addr, value) - store ((zword) (value & mask)); + /* Exit if the property does not exist */ + if ((value & mask) != zargs[1]) + runtime_error(ERR_NO_PROP); + } -}/* z_get_next_prop */ + /* Return the property id */ + LOW_BYTE(prop_addr, value) + store((zword) (value & mask)); +} /* z_get_next_prop */ /* @@ -484,56 +427,47 @@ void z_get_next_prop (void) * zargs[0] = object * */ -void z_get_parent (void) +void z_get_parent(void) { - zword obj_addr; - - /* If we are monitoring object locating display a short note */ - - if (f_setup.object_locating) { - stream_mssg_on (); - print_string ("@get_parent "); - print_object (zargs[0]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_GET_PARENT_0); - store (0); - return; - } - - obj_addr = object_address (zargs[0]); - - if (h_version <= V3) { - - zbyte parent; + zword obj_addr; - /* Get parent id from object */ + /* If we are monitoring object locating display a short note */ - obj_addr += O1_PARENT; - LOW_BYTE (obj_addr, parent) - - /* Store parent */ - - store (parent); - - } else { + if (f_setup.object_locating) { + stream_mssg_on(); + print_string("@get_parent "); + print_object(zargs[0]); + stream_mssg_off(); + } - zword parent; + if (zargs[0] == 0) { + runtime_error(ERR_GET_PARENT_0); + store(0); + return; + } - /* Get parent id from object */ + obj_addr = object_address (zargs[0]); - obj_addr += O4_PARENT; - LOW_WORD (obj_addr, parent) + if (h_version <= V3) { + zbyte parent; - /* Store parent */ + /* Get parent id from object */ + obj_addr += O1_PARENT; + LOW_BYTE(obj_addr, parent) - store (parent); + /* Store parent */ + store(parent); + } else { + zword parent; - } + /* Get parent id from object */ + obj_addr += O4_PARENT; + LOW_WORD (obj_addr, parent) -}/* z_get_parent */ + /* Store parent */ + store (parent); + } +} /* z_get_parent */ /* @@ -543,64 +477,51 @@ void z_get_parent (void) * zargs[1] = number of property to be examined * */ -void z_get_prop (void) +void z_get_prop(void) { - zword prop_addr; - zword wprop_val; - zbyte bprop_val; - zbyte value; - zbyte mask; - - if (zargs[0] == 0) { - runtime_error (ERR_GET_PROP_0); - store (0); - return; - } - - /* Property id is in bottom five (six) bits */ - - mask = (h_version <= V3) ? 0x1f : 0x3f; - - /* Load address of first property */ - - prop_addr = first_property (zargs[0]); - - /* Scan down the property list */ - - for (;;) { - LOW_BYTE (prop_addr, value) - if ((value & mask) <= zargs[1]) - break; - prop_addr = next_property (prop_addr); - } - - if ((value & mask) == zargs[1]) { /* property found */ - - /* Load property (byte or word sized) */ - - prop_addr++; - - if ((h_version <= V3 && !(value & 0xe0)) || (h_version >= V4 && !(value & 0xc0))) { - - LOW_BYTE (prop_addr, bprop_val) - wprop_val = bprop_val; - - } else LOW_WORD (prop_addr, wprop_val) - - } else { /* property not found */ - - /* Load default value */ - - prop_addr = h_objects + 2 * (zargs[1] - 1); - LOW_WORD (prop_addr, wprop_val) + zword prop_addr; + zword wprop_val; + zbyte bprop_val; + zbyte value; + zbyte mask; + + if (zargs[0] == 0) { + runtime_error(ERR_GET_PROP_0); + store(0); + return; + } - } + /* Property id is in bottom five (six) bits */ + mask = (h_version <= V3) ? 0x1f : 0x3f; - /* Store the property value */ + /* Load address of first property */ + prop_addr = first_property(zargs[0]); - store (wprop_val); + /* Scan down the property list */ + for (;;) { + LOW_BYTE(prop_addr, value) + if ((value & mask) <= zargs[1]) + break; + prop_addr = next_property(prop_addr); + } -}/* z_get_prop */ + if ((value & mask) == zargs[1]) { /* property found */ + /* Load property (byte or word sized) */ + prop_addr++; + if ((h_version <= V3 && !(value & 0xe0)) || + (h_version >= V4 && !(value & 0xc0))) { + LOW_BYTE(prop_addr, bprop_val) + wprop_val = bprop_val; + } else + LOW_WORD(prop_addr, wprop_val) + } else { /* property not found */ + /* Load default value */ + prop_addr = h_objects + 2 * (zargs[1] - 1); + LOW_WORD(prop_addr, wprop_val) + } + /* Store the property value */ + store (wprop_val); +} /* z_get_prop */ /* @@ -610,50 +531,47 @@ void z_get_prop (void) * zargs[1] = number of property to be examined * */ -void z_get_prop_addr (void) +void z_get_prop_addr(void) { - zword prop_addr; - zbyte value; - zbyte mask; - - if (zargs[0] == 0) { - runtime_error (ERR_GET_PROP_ADDR_0); - store (0); - return; - } - - if (story_id == BEYOND_ZORK) - if (zargs[0] > MAX_OBJECT) - { store (0); return; } - - /* Property id is in bottom five (six) bits */ - - mask = (h_version <= V3) ? 0x1f : 0x3f; - - /* Load address of first property */ - - prop_addr = first_property (zargs[0]); - - /* Scan down the property list */ - - for (;;) { - LOW_BYTE (prop_addr, value) - if ((value & mask) <= zargs[1]) - break; - prop_addr = next_property (prop_addr); - } + zword prop_addr; + zbyte value; + zbyte mask; + + if (zargs[0] == 0) { + runtime_error(ERR_GET_PROP_ADDR_0); + store(0); + return; + } - /* Calculate the property address or return zero */ + if (story_id == BEYOND_ZORK) { + if (zargs[0] > MAX_OBJECT) { + store (0); + return; + } + } - if ((value & mask) == zargs[1]) { + /* Property id is in bottom five (six) bits */ + mask = (h_version <= V3) ? 0x1f : 0x3f; - if (h_version >= V4 && (value & 0x80)) - prop_addr++; - store ((zword) (prop_addr + 1)); + /* Load address of first property */ + prop_addr = first_property(zargs[0]); - } else store (0); + /* Scan down the property list */ + for (;;) { + LOW_BYTE(prop_addr, value) + if ((value & mask) <= zargs[1]) + break; + prop_addr = next_property(prop_addr); + } -}/* z_get_prop_addr */ + /* Calculate the property address or return zero */ + if ((value & mask) == zargs[1]) { + if (h_version >= V4 && (value & 0x80)) + prop_addr++; + store ((zword) (prop_addr + 1)); + } else + store (0); +} /* z_get_prop_addr */ /* @@ -662,40 +580,33 @@ void z_get_prop_addr (void) * zargs[0] = address of property to be examined * */ -void z_get_prop_len (void) +void z_get_prop_len(void) { - zword addr; - zbyte value; - - if (zargs[0] == 0) { - store (0); /* demanded by Spec 1.1 */ - return; - } - - /* Back up the property pointer to the property id */ - - addr = zargs[0] - 1; - LOW_BYTE (addr, value) - - /* Calculate length of property */ - - if (h_version <= V3) - value = (value >> 5) + 1; - else if (!(value & 0x80)) - value = (value >> 6) + 1; - else { - - value &= 0x3f; - - if (value == 0) value = 64; /* demanded by Spec 1.0 */ + zword addr; + zbyte value; - } + if (zargs[0] == 0) { + store(0); /* demanded by Spec 1.1 */ + return; + } - /* Store length of property */ + /* Back up the property pointer to the property id */ + addr = zargs[0] - 1; + LOW_BYTE(addr, value) - store (value); + /* Calculate length of property */ + if (h_version <= V3) + value = (value >> 5) + 1; + else if (!(value & 0x80)) + value = (value >> 6) + 1; + else { + value &= 0x3f; + if (value == 0) value = 64; /* demanded by Spec 1.0 */ -}/* z_get_prop_len */ + } + /* Store length of property */ + store(value); +} /* z_get_prop_len */ /* @@ -704,50 +615,42 @@ void z_get_prop_len (void) * zargs[0] = object * */ -void z_get_sibling (void) +void z_get_sibling(void) { - zword obj_addr; - - if (zargs[0] == 0) { - runtime_error (ERR_GET_SIBLING_0); - store (0); - branch (FALSE); - return; - } - - obj_addr = object_address (zargs[0]); - - if (h_version <= V3) { + zword obj_addr; - zbyte sibling; - - /* Get sibling id from object */ - - obj_addr += O1_SIBLING; - LOW_BYTE (obj_addr, sibling) - - /* Store sibling and branch */ - - store (sibling); - branch (sibling); - - } else { + if (zargs[0] == 0) { + runtime_error(ERR_GET_SIBLING_0); + store(0); + branch(FALSE); + return; + } - zword sibling; + obj_addr = object_address(zargs[0]); - /* Get sibling id from object */ + if (h_version <= V3) { + zbyte sibling; - obj_addr += O4_SIBLING; - LOW_WORD (obj_addr, sibling) + /* Get sibling id from object */ + obj_addr += O1_SIBLING; + LOW_BYTE(obj_addr, sibling) - /* Store sibling and branch */ + /* Store sibling and branch */ + store(sibling); + branch(sibling); + } else { + zword sibling; - store (sibling); - branch (sibling); + /* Get sibling id from object */ + obj_addr += O4_SIBLING; + LOW_WORD(obj_addr, sibling) - } + /* Store sibling and branch */ + store(sibling); + branch(sibling); + } -}/* z_get_sibling */ +} /* z_get_sibling */ /* @@ -757,72 +660,63 @@ void z_get_sibling (void) * zargs[1] = destination object * */ -void z_insert_obj (void) +void z_insert_obj(void) { - zword obj1 = zargs[0]; - zword obj2 = zargs[1]; - zword obj1_addr; - zword obj2_addr; - - /* If we are monitoring object movements display a short note */ - - if (f_setup.object_movement) { - stream_mssg_on (); - print_string ("@move_obj "); - print_object (obj1); - print_string (" "); - print_object (obj2); - stream_mssg_off (); - } - - if (obj1 == 0) { - runtime_error (ERR_MOVE_OBJECT_0); - return; - } - - if (obj2 == 0) { - runtime_error (ERR_MOVE_OBJECT_TO_0); - return; - } - - /* Get addresses of both objects */ - - obj1_addr = object_address (obj1); - obj2_addr = object_address (obj2); - - /* Remove object 1 from current parent */ - - unlink_object (obj1); - - /* Make object 1 first child of object 2 */ - - if (h_version <= V3) { - - zbyte child; - - obj1_addr += O1_PARENT; - SET_BYTE (obj1_addr, obj2) - obj2_addr += O1_CHILD; - LOW_BYTE (obj2_addr, child) - SET_BYTE (obj2_addr, obj1) - obj1_addr += O1_SIBLING - O1_PARENT; - SET_BYTE (obj1_addr, child) - - } else { - - zword child; + zword obj1 = zargs[0]; + zword obj2 = zargs[1]; + zword obj1_addr; + zword obj2_addr; + + /* If we are monitoring object movements display a short note */ + if (f_setup.object_movement) { + stream_mssg_on(); + print_string("@move_obj "); + print_object(obj1); + print_string(" "); + print_object(obj2); + stream_mssg_off(); + } - obj1_addr += O4_PARENT; - SET_WORD (obj1_addr, obj2) - obj2_addr += O4_CHILD; - LOW_WORD (obj2_addr, child) - SET_WORD (obj2_addr, obj1) - obj1_addr += O4_SIBLING - O4_PARENT; - SET_WORD (obj1_addr, child) + if (obj1 == 0) { + runtime_error(ERR_MOVE_OBJECT_0); + return; + } - } + if (obj2 == 0) { + runtime_error(ERR_MOVE_OBJECT_TO_0); + return; + } -}/* z_insert_obj */ + /* Get addresses of both objects */ + obj1_addr = object_address(obj1); + obj2_addr = object_address(obj2); + + /* Remove object 1 from current parent */ + unlink_object(obj1); + + /* Make object 1 first child of object 2 */ + if (h_version <= V3) { + zbyte child; + + obj1_addr += O1_PARENT; + SET_BYTE(obj1_addr, obj2) + obj2_addr += O1_CHILD; + LOW_BYTE(obj2_addr, child) + SET_BYTE(obj2_addr, obj1) + obj1_addr += O1_SIBLING - O1_PARENT; + SET_BYTE(obj1_addr, child) + } else { + zword child; + + obj1_addr += O4_PARENT; + SET_WORD(obj1_addr, obj2) + obj2_addr += O4_CHILD; + LOW_WORD(obj2_addr, child) + SET_WORD(obj2_addr, obj1) + obj1_addr += O4_SIBLING - O4_PARENT; + SET_WORD(obj1_addr, child) + } +} /* z_insert_obj */ /* @@ -833,52 +727,47 @@ void z_insert_obj (void) * zargs[2] = value to set property to * */ -void z_put_prop (void) +void z_put_prop(void) { - zword prop_addr; - zword value; - zbyte mask; - - if (zargs[0] == 0) { - runtime_error (ERR_PUT_PROP_0); - return; - } - - /* Property id is in bottom five or six bits */ - - mask = (h_version <= V3) ? 0x1f : 0x3f; + zword prop_addr; + zword value; + zbyte mask; - /* Load address of first property */ - - prop_addr = first_property (zargs[0]); - - /* Scan down the property list */ - - for (;;) { - LOW_BYTE (prop_addr, value) - if ((value & mask) <= zargs[1]) - break; - prop_addr = next_property (prop_addr); - } + if (zargs[0] == 0) { + runtime_error(ERR_PUT_PROP_0); + return; + } - /* Exit if the property does not exist */ + /* Property id is in bottom five or six bits */ + mask = (h_version <= V3) ? 0x1f : 0x3f; - if ((value & mask) != zargs[1]) - runtime_error (ERR_NO_PROP); + /* Load address of first property */ + prop_addr = first_property(zargs[0]); - /* Store the new property value (byte or word sized) */ + /* Scan down the property list */ + for (;;) { + LOW_BYTE(prop_addr, value) + if ((value & mask) <= zargs[1]) + break; + prop_addr = next_property (prop_addr); + } - prop_addr++; + /* Exit if the property does not exist */ + if ((value & mask) != zargs[1]) + runtime_error(ERR_NO_PROP); - if ((h_version <= V3 && !(value & 0xe0)) || (h_version >= V4 && !(value & 0xc0))) { - zbyte v = zargs[2]; - SET_BYTE (prop_addr, v) - } else { - zword v = zargs[2]; - SET_WORD (prop_addr, v) - } + /* Store the new property value (byte or word sized) */ + prop_addr++; -}/* z_put_prop */ + if ((h_version <= V3 && !(value & 0xe0)) || + (h_version >= V4 && !(value & 0xc0))) { + zbyte v = zargs[2]; + SET_BYTE(prop_addr, v) + } else { + zword v = zargs[2]; + SET_WORD(prop_addr, v) + } +} /* z_put_prop */ /* @@ -889,20 +778,17 @@ void z_put_prop (void) */ void z_remove_obj (void) { - /* If we are monitoring object movements display a short note */ - - if (f_setup.object_movement) { - stream_mssg_on (); - print_string ("@remove_obj "); - print_object (zargs[0]); - stream_mssg_off (); - } - - /* Call unlink_object to do the job */ - - unlink_object (zargs[0]); + /* If we are monitoring object movements display a short note */ + if (f_setup.object_movement) { + stream_mssg_on(); + print_string("@remove_obj "); + print_object(zargs[0]); + stream_mssg_off(); + } -}/* z_remove_obj */ + /* Call unlink_object to do the job */ + unlink_object(zargs[0]); +} /* z_remove_obj */ /* @@ -912,51 +798,45 @@ void z_remove_obj (void) * zargs[1] = number of attribute to set * */ -void z_set_attr (void) +void z_set_attr(void) { zword obj_addr; zbyte value; - if (story_id == SHERLOCK) - if (zargs[1] == 48) - return; - - if (zargs[1] > ((h_version <= V3) ? 31 : 47)) - runtime_error (ERR_ILL_ATTR); - - /* If we are monitoring attribute assignment display a short note */ - - if (f_setup.attribute_assignment) { - stream_mssg_on (); - print_string ("@set_attr "); - print_object (zargs[0]); - print_string (" "); - print_num (zargs[1]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_SET_ATTR_0); - return; - } - - /* Get attribute address */ - - obj_addr = object_address (zargs[0]) + zargs[1] / 8; - - /* Load attribute byte */ - - LOW_BYTE (obj_addr, value) + if (story_id == SHERLOCK) + if (zargs[1] == 48) + return; + + if (zargs[1] > ((h_version <= V3) ? 31 : 47)) + runtime_error(ERR_ILL_ATTR); + + /* If we are monitoring attribute assignment display a short note */ + if (f_setup.attribute_assignment) { + stream_mssg_on(); + print_string("@set_attr "); + print_object(zargs[0]); + print_string(" "); + print_num(zargs[1]); + stream_mssg_off(); + } - /* Set attribute bit */ + if (zargs[0] == 0) { + runtime_error(ERR_SET_ATTR_0); + return; + } - value |= 0x80 >> (zargs[1] & 7); + /* Get attribute address */ + obj_addr = object_address(zargs[0]) + zargs[1] / 8; - /* Store attribute byte */ + /* Load attribute byte */ + LOW_BYTE(obj_addr, value) - SET_BYTE (obj_addr, value) + /* Set attribute bit */ + value |= 0x80 >> (zargs[1] & 7); -}/* z_set_attr */ + /* Store attribute byte */ + SET_BYTE(obj_addr, value) +} /* z_set_attr */ /* @@ -966,41 +846,36 @@ void z_set_attr (void) * zargs[1] = number of attribute to test * */ -void z_test_attr (void) +void z_test_attr(void) { - zword obj_addr; - zbyte value; - - if (zargs[1] > ((h_version <= V3) ? 31 : 47)) - runtime_error (ERR_ILL_ATTR); - - /* If we are monitoring attribute testing display a short note */ - - if (f_setup.attribute_testing) { - stream_mssg_on (); - print_string ("@test_attr "); - print_object (zargs[0]); - print_string (" "); - print_num (zargs[1]); - stream_mssg_off (); - } - - if (zargs[0] == 0) { - runtime_error (ERR_TEST_ATTR_0); - branch (FALSE); - return; - } - - /* Get attribute address */ - - obj_addr = object_address (zargs[0]) + zargs[1] / 8; - - /* Load attribute byte */ + zword obj_addr; + zbyte value; + + if (zargs[1] > ((h_version <= V3) ? 31 : 47)) + runtime_error(ERR_ILL_ATTR); + + /* If we are monitoring attribute testing display a short note */ + if (f_setup.attribute_testing) { + stream_mssg_on(); + print_string("@test_attr "); + print_object(zargs[0]); + print_string(" "); + print_num(zargs[1]); + stream_mssg_off(); + } + if (zargs[0] == 0) { + runtime_error(ERR_TEST_ATTR_0); + branch(FALSE); + return; + } - LOW_BYTE (obj_addr, value) + /* Get attribute address */ + obj_addr = object_address(zargs[0]) + zargs[1] / 8; - /* Test attribute */ + /* Load attribute byte */ + LOW_BYTE(obj_addr, value) - branch (value & (0x80 >> (zargs[1] & 7))); + /* Test attribute */ + branch (value & (0x80 >> (zargs[1] & 7))); -}/* z_test_attr */ +} /* z_test_attr */ -- 2.34.1