Exemplo n.º 1
0
        }/* memory_word */

        /*
         * memory_close
         *
         * End of output redirection.
         *
         */

        internal static void memory_close()
        {
            if (depth >= 0)
            {
                if (redirect[depth].xsize != 0xffff)
                {
                    memory_new_line();
                }

                if (main.h_version == ZMachine.V6)
                {
                    main.h_line_width = (redirect[depth].xsize != 0xffff) ?
                                        redirect[depth].total : redirect[depth].width;

                    FastMem.SET_WORD(ZMachine.H_LINE_WIDTH, main.h_line_width);
                }

                if (depth == 0)
                {
                    main.ostream_memory = false;
                }

                depth--;
            }
        }/* memory_close */
Exemplo n.º 2
0
        }/* script_open */

        /*
         * script_close
         *
         * Stop transscription.
         *
         */

        internal static void script_close()
        {
            main.h_flags &= (ushort)~ZMachine.SCRIPTING_FLAG;
            FastMem.SET_WORD(ZMachine.H_FLAGS, main.h_flags);

            sfp.Close();
            main.ostream_script = false;
        }/* script_close */
Exemplo n.º 3
0
        }/* z_insert_obj */

        /*
         * z_put_prop, set the value of an object property.
         *
         *	Process.zargs[0] = object
         *	Process.zargs[1] = number of property to set
         *	Process.zargs[2] = value to set property to
         *
         */

        internal static void z_put_prop()
        {
            zword prop_addr;
            zbyte value;
            zbyte mask;

            if (Process.zargs[0] == 0)
            {
                Err.runtime_error(ErrorCodes.ERR_PUT_PROP_0);
                return;
            }

            /* Property id is in bottom five or six bits */

            mask = (zbyte)((main.h_version <= ZMachine.V3) ? 0x1f : 0x3f);

            /* Load address of first property */

            prop_addr = first_property(Process.zargs[0]);

            /* Scan down the property list */

            for (; ;)
            {
                FastMem.LOW_BYTE(prop_addr, out value);
                if ((value & mask) <= Process.zargs[1])
                {
                    break;
                }
                prop_addr = next_property(prop_addr);
            }

            /* Exit if the property does not exist */

            if ((value & mask) != Process.zargs[1])
            {
                Err.runtime_error(ErrorCodes.ERR_NO_PROP);
            }

            /* Store the new property value (byte or word sized) */

            prop_addr++;

            if ((main.h_version <= ZMachine.V3 && !((value & 0xe0) > 0)) || (main.h_version >= ZMachine.V4 && !((value & 0xc0) > 0)))
            {
                zbyte v = (zbyte)Process.zargs[2];
                FastMem.SET_BYTE(prop_addr, v);
            }
            else
            {
                zword v = Process.zargs[2];
                FastMem.SET_WORD(prop_addr, v);
            }
        }/* z_put_prop */
Exemplo n.º 4
0
        }/* z_pop_stack */

        /*
         * z_pull, pop a value off...
         *
         * a) ...the game or a user stack and store it (V6)
         *
         *	zargs[0] = address of user stack (optional)
         *
         * b) ...the game stack and write it to a variable (other than V6)
         *
         *	zargs[0] = variable to write value to
         *
         */

        internal static void z_pull()
        {
            zword value;

            if (main.h_version != ZMachine.V6)          /* not a V6 game, pop stack and write */

            {
                value = main.stack[main.sp++];

                if (Process.zargs[0] == 0)
                {
                    main.stack[main.sp] = value;
                }
                else if (Process.zargs[0] < 16)
                {
                    // *(fp - Process.zargs[0]) = value;
                    main.stack[main.fp - Process.zargs[0]] = value;
                }
                else
                {
                    zword addr = (zword)(main.h_globals + 2 * (Process.zargs[0] - 16));
                    FastMem.SET_WORD(addr, value);
                }
            }
            else                        /* it's V6, but is there a user stack? */

            {
                if (Process.zargc == 1)         /* it's a user stack */

                {
                    zword size;
                    zword addr = Process.zargs[0];

                    FastMem.LOW_WORD(addr, out size);

                    size++;
                    FastMem.storew(addr, size);

                    addr += (zword)(2 * size);
                    FastMem.LOW_WORD(addr, out value);
                }
                else
                {
                    value = main.stack[main.sp++];   // value = *sp++;	/* it's the game stack */
                }
                Process.store(value);
            }
        }/* z_pull */
Exemplo n.º 5
0
        }/* z_push_stack */

        /*
         * z_store, write a value to a variable.
         *
         *  zargs[0] = variable to be written to
         *      zargs[1] = value to write
         *
         */

        internal static void z_store()
        {
            zword value = Process.zargs[1];

            if (Process.zargs[0] == 0)
            {
                main.stack[main.sp] = value;
            }
            else if (Process.zargs[0] < 16)
            {
                main.stack[main.fp - Process.zargs[0]] = value;
            }
            else
            {
                zword addr = (zword)(main.h_globals + 2 * (Process.zargs[0] - 16));
                FastMem.SET_WORD(addr, value);
            }
        }/* z_store */
Exemplo n.º 6
0
        }/* z_dec_chk */

        /*
         * z_inc, increment a variable.
         *
         *  zargs[0] = variable to increment
         *
         */

        internal static void z_inc()
        {
            zword value;

            if (Process.zargs[0] == 0)
            {
                main.stack[main.sp]++; // (*sp)++;
            }
            else if (Process.zargs[0] < 16)
            {
                (main.stack[main.fp - Process.zargs[0]])++;
            }
            else
            {
                zword addr = (zword)(main.h_globals + 2 * (Process.zargs[0] - 16));
                FastMem.LOW_WORD(addr, out value);
                value++;
                FastMem.SET_WORD(addr, value);
            }
        }/* z_inc */
Exemplo n.º 7
0
        }/* z_dec */

        /*
         * z_dec_chk, decrement a variable and branch if now less than value.
         *
         *  zargs[0] = variable to decrement
         *  zargs[1] = value to check variable against
         *
         */

        internal static void z_dec_chk()
        {
            zword value;

            if (Process.zargs[0] == 0)
            {
                value = --(main.stack[main.sp]);
            }
            else if (Process.zargs[0] < 16)
            {
                value = --(main.stack[main.fp - Process.zargs[0]]);
            }
            else
            {
                zword addr = (zword)(main.h_globals + 2 * (Process.zargs[0] - 16));
                FastMem.LOW_WORD(addr, out value);
                value--;
                FastMem.SET_WORD(addr, value);
            }

            Process.branch((short)value < (short)Process.zargs[1]);
        }/* z_dec_chk */
Exemplo n.º 8
0
        }/* branch */

        /*
         * store
         *
         * Store an operand, either as a variable or pushed on the stack.
         *
         */

        internal static void store(zword value)
        {
            zbyte variable;

            FastMem.CODE_BYTE(out variable);

            if (variable == 0)
            {
                main.stack[--main.sp] = value; // *--sp = value;
                DebugState.Output("  Storing {0} on stack at {1}", value, main.sp);
            }
            else if (variable < 16)
            {
                main.stack[main.fp - variable] = value;  // *(fp - variable) = value;
                DebugState.Output("  Storing {0} on stack as Variable {1} at {2}", value, variable, main.sp);
            }
            else
            {
                zword addr = (zword)(main.h_globals + 2 * (variable - 16));
                FastMem.SET_WORD(addr, value);
                DebugState.Output("  Storing {0} at {1}", value, addr);
            }
        }/* store */
Exemplo n.º 9
0
        internal static void script_open()
        {
            string new_name = null;

            main.h_flags &= (zword) ~ZMachine.SCRIPTING_FLAG;

            if (main.h_version >= ZMachine.V5 || !script_valid)
            {
                if (os_.read_file_name(out new_name, General.DEFAULT_SCRIPT_NAME, FileTypes.FILE_SCRIPT) != true)
                {
                    goto done;
                }

                script_name = new_name;
            }

            if ((sfp = new System.IO.StreamWriter(script_name, true)) != null)
            {
                main.h_flags |= ZMachine.SCRIPTING_FLAG;

                script_valid        = true;
                main.ostream_script = true;

                script_width = 0;

                sfp.AutoFlush = true;
            }
            else
            {
                Text.print_string("Cannot open file\n");
            }

done:

            FastMem.SET_WORD(ZMachine.H_FLAGS, main.h_flags);
        }/* script_open */
Exemplo n.º 10
0
        }/* z_get_sibling */

        /*
         * z_insert_obj, make an object the first child of another object.
         *
         *	Process.zargs[0] = object to be moved
         *	Process.zargs[1] = destination object
         *
         */

        internal static void z_insert_obj()
        {
            zword obj1 = Process.zargs[0];
            zword obj2 = Process.zargs[1];
            zword obj1_addr;
            zword obj2_addr;

            /* If we are monitoring object movements display a short note */

            if (main.option_object_movement == true)
            {
                Stream.stream_mssg_on();
                Text.print_string("@move_obj ");
                Text.print_object(obj1);
                Text.print_string(" ");
                Text.print_object(obj2);
                Stream.stream_mssg_off();
            }

            if (obj1 == 0)
            {
                Err.runtime_error(ErrorCodes.ERR_MOVE_OBJECT_0);
                return;
            }

            if (obj2 == 0)
            {
                Err.runtime_error(ErrorCodes.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 (main.h_version <= ZMachine.V3)
            {
                zbyte child;

                obj1_addr += O1_PARENT;
                FastMem.SET_BYTE(obj1_addr, (zbyte)obj2);
                obj2_addr += O1_CHILD;
                FastMem.LOW_BYTE(obj2_addr, out child);
                FastMem.SET_BYTE(obj2_addr, (zbyte)obj1);
                obj1_addr += (zword)(O1_SIBLING - O1_PARENT);
                FastMem.SET_BYTE(obj1_addr, child);
            }
            else
            {
                zword child;

                obj1_addr += O4_PARENT;
                FastMem.SET_WORD(obj1_addr, obj2);
                obj2_addr += O4_CHILD;
                FastMem.LOW_WORD(obj2_addr, out child);
                FastMem.SET_WORD(obj2_addr, obj1);
                obj1_addr += (zword)(O4_SIBLING - O4_PARENT);
                FastMem.SET_WORD(obj1_addr, child);
            }
        }/* z_insert_obj */
Exemplo n.º 11
0
        }/* next_property */

        /*
         * unlink_object
         *
         * Unlink an object from its parent and siblings.
         *
         */

        static void unlink_object(zword object_var)
        {
            zword obj_addr;
            zword parent_addr;
            zword sibling_addr;

            if (object_var == 0)
            {
                Err.runtime_error(ErrorCodes.ERR_REMOVE_OBJECT_0);
                return;
            }

            obj_addr = object_address(object_var);

            if (main.h_version <= ZMachine.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;
                FastMem.LOW_BYTE(obj_addr, out parent);
                if (parent == 0)
                {
                    return;
                }

                /* Get (older) sibling of object and set both parent and sibling
                 * pointers to 0 */

                FastMem.SET_BYTE(obj_addr, zero);
                obj_addr += (zword)(O1_SIBLING - O1_PARENT);
                FastMem.LOW_BYTE(obj_addr, out older_sibling);
                FastMem.SET_BYTE(obj_addr, zero);

                /* Get first child of parent (the youngest sibling of the object) */

                parent_addr = (zword)(object_address(parent) + O1_CHILD);
                FastMem.LOW_BYTE(parent_addr, out younger_sibling);

                /* Remove object from the list of siblings */

                if (younger_sibling == object_var)
                {
                    FastMem.SET_BYTE(parent_addr, older_sibling);
                }
                else
                {
                    do
                    {
                        sibling_addr = (zword)(object_address(younger_sibling) + O1_SIBLING);
                        FastMem.LOW_BYTE(sibling_addr, out younger_sibling);
                    } while (younger_sibling != object_var);
                    FastMem.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;
                FastMem.LOW_WORD(obj_addr, out parent);
                if (parent == 0)
                {
                    return;
                }

                /* Get (older) sibling of object and set both parent and sibling
                 * pointers to 0 */

                FastMem.SET_WORD(obj_addr, zero);
                obj_addr += (zword)(O4_SIBLING - O4_PARENT);
                FastMem.LOW_WORD(obj_addr, out older_sibling);
                FastMem.SET_WORD(obj_addr, zero);

                /* Get first child of parent (the youngest sibling of the object) */

                parent_addr = (zword)(object_address(parent) + O4_CHILD);
                FastMem.LOW_WORD(parent_addr, out younger_sibling);

                /* Remove object from the list of siblings */

                if (younger_sibling == object_var)
                {
                    FastMem.SET_WORD(parent_addr, older_sibling);
                }
                else
                {
                    do
                    {
                        sibling_addr = (zword)(object_address(younger_sibling) + O4_SIBLING);
                        FastMem.LOW_WORD(sibling_addr, out younger_sibling);
                    } while (younger_sibling != object_var);
                    FastMem.SET_WORD(sibling_addr, older_sibling);
                }
            }
        }/* unlink_object */