示例#1
0
        }/* read_number */

        /*
         * z_read, read a line of input and (in V5+) store the terminating key.
         *
         *	zargs[0] = address of text buffer
         *	zargs[1] = address of token buffer
         *	zargs[2] = timeout in tenths of a second (optional)
         *	zargs[3] = packed address of routine to be called on timeout
         *
         */

        internal static void z_read()
        {
            zword[] buffer = new zword[General.INPUT_BUFFER_SIZE];
            zword   addr;
            zword   key;
            zbyte   max, size;
            zbyte   c;
            int     i;

            /* Supply default arguments */

            if (Process.zargc < 3)
            {
                Process.zargs[2] = 0;
            }

            /* Get maximum input size */

            addr = Process.zargs[0];

            FastMem.LOW_BYTE(addr, out max);

            if (main.h_version <= ZMachine.V4)
            {
                max--;
            }

            if (max >= General.INPUT_BUFFER_SIZE)
            {
                max = (zbyte)(General.INPUT_BUFFER_SIZE - 1);
            }

            /* Get initial input size */

            if (main.h_version >= ZMachine.V5)
            {
                addr++;
                FastMem.LOW_BYTE(addr, out size);
            }
            else
            {
                size = 0;
            }

            /* Copy initial input to local buffer */

            for (i = 0; i < size; i++)
            {
                addr++;
                FastMem.LOW_BYTE(addr, out c);
                buffer[i] = Text.translate_from_zscii(c);
            }

            buffer[i] = 0;

            /* Draw status line for V1 to V3 games */

            if (main.h_version <= ZMachine.V3)
            {
                Screen.z_show_status();
            }

            /* Read input from current input stream */

            key = Stream.stream_read_input(
                max, buffer,                    /* buffer and size */
                Process.zargs[2],               /* timeout value   */
                Process.zargs[3],               /* timeout routine */
                true,                           /* enable hot keys */
                main.h_version == ZMachine.V6); /* no script in V6 */

            if (key == CharCodes.ZC_BAD)
            {
                return;
            }

            /* Perform save_undo for V1 to V4 games */

            if (main.h_version <= ZMachine.V4)
            {
                FastMem.save_undo();
            }

            /* Copy local buffer back to dynamic memory */

            for (i = 0; buffer[i] != 0; i++)
            {
                if (key == CharCodes.ZC_RETURN)
                {
                    buffer[i] = Text.unicode_tolower(buffer[i]);
                }

                FastMem.storeb((zword)(Process.zargs[0] + ((main.h_version <= ZMachine.V4) ? 1 : 2) + i), Text.translate_to_zscii(buffer[i]));
            }

            /* Add null character (V1-V4) or write input length into 2nd byte */

            if (main.h_version <= ZMachine.V4)
            {
                FastMem.storeb((zword)(Process.zargs[0] + 1 + i), 0);
            }
            else
            {
                FastMem.storeb((zword)(Process.zargs[0] + 1), (byte)i);
            }

            /* Tokenise line if a token buffer is present */

            if (key == CharCodes.ZC_RETURN && Process.zargs[1] != 0)
            {
                Text.tokenise_line(Process.zargs[0], Process.zargs[1], 0, false);
            }

            /* Store key */

            if (main.h_version >= ZMachine.V5)
            {
                Process.store(Text.translate_to_zscii(key));
            }
        }/* z_read */